Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support overriding the Prev time for a new job/entry #446

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dominicbarnes
Copy link

@dominicbarnes dominicbarnes commented Apr 28, 2022

This PR adds a new capability to override the default "prev" time for a job during create, which has a number of useful applications.

First, it allows a schedule to be preserved across process restarts, keeping interval-based jobs from all being interrupted each time. The extra work needed to store/retrieve these timestamps is out of scope for this library, but this change allows that feature where it could not be done before. This could be considered a solution to #336.

Second, this can be a quick-and-dirty way to trigger jobs immediately, by simply choosing a "prev" time that is sufficiently far back in the past. It's a little janky, but there are tons of issues submitted about this very issue so I believe that utility would provide value. (this could be considered as an alternative fix for #436, #422, #406, #297, #396, #439, #356, #342, #336 and possibly others)

This is accomplished via a new ...EntryOption parameter for Cron.AddJob, Cron.AddFunc and Cron.Schedule, which isn't technically backwards compatible, as the function signature does change, but most code shouldn't need to be altered. This pattern mirrors New(...Option) Cron in structure, rather than trying to do something new. Currently, the only available option is WithPrev that sets Entry.Job before scheduling the job for the first time, but there could be room to add additional configurations if needed.

Additionally, Cron now considers the possibility that Entry.Prev may be nonzero, and will check that first, otherwise falling back on the current behavior of "now". In short, this is an opt-in feature, and should not change default behavior.

SamPeng87 pushed a commit to SamPeng87/cron that referenced this pull request May 9, 2022
fufuok added a commit to fufuok/cron that referenced this pull request Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant