refactor: change retry task to use the same job UUID, so we can track then

This commit is contained in:
Derrick Hammer 2024-01-28 16:39:04 -05:00
parent 4bb34315eb
commit a2ee46dbb3
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 12 additions and 1 deletions

View File

@ -50,6 +50,7 @@ type RetryableTaskParams struct {
}
type CronJob struct {
JobId uuid.UUID
Job gocron.JobDefinition
Task gocron.Task
Options []gocron.JobOption
@ -122,8 +123,9 @@ func (c *CronServiceImpl) RetryableTask(params RetryableTaskParams) CronJob {
taskRetry.Attempt++
retryTask := c.RetryableTask(taskRetry)
retryTask.JobId = jobID
_, err = c.CreateJob(retryTask)
_, err = c.RerunJob(retryTask)
if err != nil {
c.logger.Error("Failed to create retry job", zap.Error(err))
}
@ -151,3 +153,12 @@ func (c *CronServiceImpl) CreateJob(job CronJob) (gocron.Job, error) {
return ret, nil
}
func (c *CronServiceImpl) RerunJob(job CronJob) (gocron.Job, error) {
ret, err := c.Scheduler().Update(job.JobId, job.Job, job.Task, job.Options...)
if err != nil {
return nil, err
}
return ret, nil
}