[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 удалений

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

@@ -5,6 +5,7 @@
package commands
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
@@ -93,7 +94,7 @@ func uploadAndProcess(c client.Client, zipPath string, isLocal bool) error {
}
// create session
us, _, err := c.CreateUpload(&model.UploadSession{
us, _, err := c.CreateUpload(context.TODO(), &model.UploadSession{
Filename: info.Name(),
FileSize: info.Size(),
Type: model.UploadTypeImport,
@@ -106,7 +107,7 @@ func uploadAndProcess(c client.Client, zipPath string, isLocal bool) error {
printer.PrintT("Upload session successfully created, ID: {{.Id}} ", us)
// upload file
finfo, _, err := c.UploadData(us.Id, zipFile)
finfo, _, err := c.UploadData(context.TODO(), us.Id, zipFile)
if err != nil {
return fmt.Errorf("failed to upload data: %w", err)
}
@@ -114,7 +115,7 @@ func uploadAndProcess(c client.Client, zipPath string, isLocal bool) error {
printer.PrintT("Import file successfully uploaded, name: {{.Name}}", finfo)
// process
job, _, err := c.CreateJob(&model.Job{
job, _, err := c.CreateJob(context.TODO(), &model.Job{
Type: model.JobTypeImportProcess,
Data: map[string]string{
"import_file": us.Id + "_" + finfo.Name,
@@ -127,7 +128,7 @@ func uploadAndProcess(c client.Client, zipPath string, isLocal bool) error {
printer.PrintT("Import process job successfully created, ID: {{.Id}}", job)
for {
job, _, err = c.GetJob(job.Id)
job, _, err = c.GetJob(context.TODO(), job.Id)
if err != nil {
return fmt.Errorf("failed to get import job status: %w", err)
}