import "time"
func waitForJob(ctx context.Context, client *reducto.Client, jobID string) (*reducto.JobGetResponse, error) {
ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-ticker.C:
job, err := client.Job.Get(ctx, jobID)
if err != nil {
return nil, err
}
if job.Status == reducto.JobGetResponseStatusCompleted {
return job, nil
} else if job.Status == reducto.JobGetResponseStatusFailed {
return nil, fmt.Errorf("job failed: %s", job.Reason)
}
fmt.Printf("Status: %s, Progress: %.0f%%\n", job.Status, job.Progress)
}
}
}
// Usage
jobResponse, _ := client.Parse.RunJob(context.Background(), params)
job, _ := waitForJob(context.Background(), client, jobResponse.JobID)
result := job.Result