cron icon indicating copy to clipboard operation
cron copied to clipboard

add support for long-term job auto remove inside the job execution

Open scbizu opened this issue 3 years ago • 2 comments

Hi there.

Since the missing support for removing job itself during the job execution , we now facing lots of the ticker leaks for our long-term cronjob. To make another job manager to refresh(or rebuild) the job lists is not easy and seems too heavy for the client-side code .

Could cron add the option job to allow us get the entryID during execution in order to remove the original job so that the ticker will be released.

I also make a pr for my proposal , we'd hope it can be merged into master ASAP.

scbizu avatar May 10 '21 03:05 scbizu

In other words, you want to schedule the job to run once, and not again?

You can do that today with something like this:

func runOnce(job cron.Job, schedule string)
  sched, _ := cron.ParseStandard("...")
  now := time.Now()
  next := sched.Next(now)
  time.Sleep(next.Sub(now))
  job()
}

robfig avatar Oct 01 '21 21:10 robfig

Not exactly , with these option we can not only making a one time job more clear , but introduce a hook-like mechanism to allow users do more things(remove,update, delayed remove or other job lifetime-related operation) with the job entryid .

scbizu avatar Oct 07 '21 06:10 scbizu