bamzi / jobrunner

Framework for performing work asynchronously, outside of the request flow
MIT License
1.04k stars 99 forks source link

[Feature Request]Expose entryID for job #29

Open halfcrazy opened 4 years ago

halfcrazy commented 4 years ago

When scheduling a job, I expected to get an entryID for this job, so I can remove this job later.

jiangytcn commented 4 years ago

you can use jobrunner.StatusPage() to extract entry id

Yc1883896 commented 4 years ago

jobrunner.StatusPage() 没有办法灵活的停止某个任务,当创建了两个同样函数的任务时,并无法进行精确的定位我要删除哪一个, 既然MainCron.Schedule(sched, New(job))公开了entry id,那么应该也有相应的返回

Ctere1 commented 3 months ago

You can use like that:

status := jobrunner.StatusJson()
jobs := status["jobrunner"].([]jobrunner.StatusData)

for _, job := range jobs {

if job.JobRunner.Name == "YOUR_JOB_NAME" {
    id := job.Id
    jobrunner.Remove(id)                                            // Remove YOUR_JOB_NAME by its ID
    err := jobrunner.Schedule(YOUR_JOB_NAME, SyncAllUsersJob{})     // Reschedule with new interval
    if err != nil {
        log.Println(err.Error())
    }
    break
    }
}