MM-49354: Make compliance export query cancellable (#21943)
We accept a context that can cancel the query. This allows us to exit a job faster. ```release-note Compliance export job can now cancel the SQL query execution during server shutdown which will allow the job to exit faster. ``` Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
40cd6b1656
Коммит
1e02b99bf1
@@ -4,6 +4,7 @@
|
||||
package sqlstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
@@ -270,7 +271,7 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance, cursor model
|
||||
return append(channelPosts, directMessagePosts...), cursor, nil
|
||||
}
|
||||
|
||||
func (s SqlComplianceStore) MessageExport(cursor model.MessageExportCursor, limit int) ([]*model.MessageExport, model.MessageExportCursor, error) {
|
||||
func (s SqlComplianceStore) MessageExport(ctx context.Context, cursor model.MessageExportCursor, limit int) ([]*model.MessageExport, model.MessageExportCursor, error) {
|
||||
var args []any
|
||||
args = append(args, model.ChannelTypeDirect, model.ChannelTypeGroup, cursor.LastPostUpdateAt, cursor.LastPostUpdateAt, cursor.LastPostId, limit)
|
||||
query :=
|
||||
@@ -317,7 +318,7 @@ func (s SqlComplianceStore) MessageExport(cursor model.MessageExportCursor, limi
|
||||
LIMIT ?`
|
||||
|
||||
cposts := []*model.MessageExport{}
|
||||
if err := s.GetReplicaX().Select(&cposts, query, args...); err != nil {
|
||||
if err := s.GetReplicaX().SelectCtx(ctx, &cposts, query, args...); err != nil {
|
||||
return nil, cursor, errors.Wrap(err, "unable to export messages")
|
||||
}
|
||||
if len(cposts) > 0 {
|
||||
|
||||
@@ -224,8 +224,12 @@ func (w *sqlxDBWrapper) QueryX(query string, args ...any) (*sqlx.Rows, error) {
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) Select(dest any, query string, args ...any) error {
|
||||
return w.SelectCtx(context.Background(), dest, query, args...)
|
||||
}
|
||||
|
||||
func (w *sqlxDBWrapper) SelectCtx(ctx context.Context, dest any, query string, args ...any) error {
|
||||
query = w.DB.Rebind(query)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), w.queryTimeout)
|
||||
ctx, cancel := context.WithTimeout(ctx, w.queryTimeout)
|
||||
defer cancel()
|
||||
|
||||
if w.trace {
|
||||
|
||||
Ссылка в новой задаче
Block a user