(currentJob string, waitJob string, stopCh chan struct{})
| 369 | } |
| 370 | |
| 371 | func (sm *StoreManager) WaitOnJob(currentJob string, waitJob string, stopCh chan struct{}) error { |
| 372 | waitCh := make(chan struct{}, 0) |
| 373 | defer close(waitCh) |
| 374 | key1 := fmt.Sprintf("dtleJobList/%v", waitJob) |
| 375 | // NB: it is OK to watch on non-existing keys. |
| 376 | ch, err := sm.consulStore.Watch(key1, waitCh) |
| 377 | if err != nil { |
| 378 | return err |
| 379 | } |
| 380 | for { |
| 381 | kv := <-ch |
| 382 | if kv == nil { |
| 383 | return fmt.Errorf("WaitOnJob get nil kv. current task might have been shutdown") |
| 384 | } |
| 385 | job := new(JobListItemV2) |
| 386 | err = json.Unmarshal(kv.Value, job) |
| 387 | if err != nil { |
| 388 | return fmt.Errorf("watch %v from consul, unmarshal err : %v", key1, err) |
| 389 | } |
| 390 | if job.JobStatus == TargetGtidFinished { |
| 391 | break |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | // update reverse job status |
| 396 | currentJobInfo, err := sm.GetJobInfo(currentJob) |
| 397 | if err != nil { |
| 398 | sm.logger.Error("job_id=%v; get job info failed: %v", currentJob, err) |
| 399 | return err |
| 400 | } else { |
| 401 | currentJobInfo.JobId = currentJob |
| 402 | currentJobInfo.JobStatus = DtleJobStatusNonPaused |
| 403 | err = sm.SaveJobInfo(*currentJobInfo) |
| 404 | if err != nil { |
| 405 | sm.logger.Error("job_id=%v; save job info failed: %v", currentJob, err) |
| 406 | return err |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | return nil |
| 411 | } |
| 412 | |
| 413 | func (sm *StoreManager) PutTargetGtid(subject string, value string) error { |
| 414 | url := fmt.Sprintf("dtle/%v/%v", subject, "targetGtid") |
no test coverage detected