[MM-49989] Pass a context.Context to Client4 methods (#22922)

* Migrate all method in model/client4.go to accept a context.Context

* Fix th.*Client

* Fix remaining issues

* Empty commit to triger CI

* Fix test

* Add cancellation test

* Test that returned error is context.Canceled

* Fix bad merge

* Update mmctl code

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Ben Schumacher
2023-06-06 23:29:29 +02:00
коммит произвёл GitHub
родитель 7116e9267a
Коммит 6c82605df0
140 изменённых файлов: 7516 добавлений и 7333 удалений

Просмотреть файл

@@ -4,6 +4,7 @@
package commands
import (
"context"
"fmt"
"io"
"os"
@@ -127,7 +128,7 @@ func exportCreateCmdF(c client.Client, command *cobra.Command, args []string) er
data["include_attachments"] = "true"
}
job, _, err := c.CreateJob(&model.Job{
job, _, err := c.CreateJob(context.TODO(), &model.Job{
Type: model.JobTypeExportProcess,
Data: data,
})
@@ -141,7 +142,7 @@ func exportCreateCmdF(c client.Client, command *cobra.Command, args []string) er
}
func exportListCmdF(c client.Client, command *cobra.Command, args []string) error {
exports, _, err := c.ListExports()
exports, _, err := c.ListExports(context.TODO())
if err != nil {
return fmt.Errorf("failed to list exports: %w", err)
}
@@ -161,7 +162,7 @@ func exportListCmdF(c client.Client, command *cobra.Command, args []string) erro
func exportDeleteCmdF(c client.Client, command *cobra.Command, args []string) error {
name := args[0]
if _, err := c.DeleteExport(name); err != nil {
if _, err := c.DeleteExport(context.TODO(), name); err != nil {
return fmt.Errorf("failed to delete export: %w", err)
}
@@ -211,7 +212,7 @@ func exportDownloadCmdF(c client.Client, command *cobra.Command, args []string)
return fmt.Errorf("failed to seek export file: %w", err)
}
if _, _, err := c.DownloadExport(name, outFile, off); err != nil {
if _, _, err := c.DownloadExport(context.TODO(), name, outFile, off); err != nil {
printer.PrintWarning(fmt.Sprintf("failed to download export file: %v. Retrying...", err))
i++
continue
@@ -231,7 +232,7 @@ func exportJobListCmdF(c client.Client, command *cobra.Command, args []string) e
}
func exportJobShowCmdF(c client.Client, command *cobra.Command, args []string) error {
job, _, err := c.GetJob(args[0])
job, _, err := c.GetJob(context.TODO(), args[0])
if err != nil {
return fmt.Errorf("failed to get export job: %w", err)
}
@@ -242,12 +243,12 @@ func exportJobShowCmdF(c client.Client, command *cobra.Command, args []string) e
}
func exportJobCancelCmdF(c client.Client, _ *cobra.Command, args []string) error {
job, _, err := c.GetJob(args[0])
job, _, err := c.GetJob(context.TODO(), args[0])
if err != nil {
return fmt.Errorf("failed to get export job: %w", err)
}
if _, err := c.CancelJob(job.Id); err != nil {
if _, err := c.CancelJob(context.TODO(), job.Id); err != nil {
return fmt.Errorf("failed to cancel export job: %w", err)
}