MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / WaitForTask

Method WaitForTask

dgraphapi/cluster.go:371–410  ·  view source on GitHub ↗

WaitForTask waits for the task to finish

(taskId string)

Source from the content-addressed store, hash-verified

369
370// WaitForTask waits for the task to finish
371func (hc *HTTPClient) WaitForTask(taskId string) error {
372 // This can happen if the backup API is a sync API
373 if taskId == "" {
374 return nil
375 }
376
377 const query = `query task($id: String!) {
378 task(input: {id: $id}) {
379 status
380 }
381 }`
382 params := GraphQLParams{
383 Query: query,
384 Variables: map[string]interface{}{"id": taskId},
385 }
386
387 for {
388 time.Sleep(waitDurBeforeRetry)
389
390 resp, err := hc.RunGraphqlQuery(params, true)
391 if err != nil {
392 return err
393 }
394
395 var statusResp struct {
396 Task struct {
397 Status string `json:"status,omitempty"`
398 } `json:"task,omitempty"`
399 }
400 if err := json.Unmarshal(resp, &statusResp); err != nil {
401 return errors.Wrap(err, "error unmarshalling status response")
402 }
403 switch statusResp.Task.Status {
404 case "Success":
405 return nil
406 case "Failed", "Unknown":
407 return fmt.Errorf("task failed with status: %s", statusResp.Task.Status)
408 }
409 }
410}
411
412// Restore performs restore on Dgraph cluster from the given path to backup
413func (hc *HTTPClient) Restore(c Cluster, backupPath string,

Callers 1

BackupMethod · 0.95

Calls 2

RunGraphqlQueryMethod · 0.95
ErrorfMethod · 0.45

Tested by

no test coverage detected