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

Pause/Continue Jobs #364

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

pradykaushik
Copy link

@pradykaushik pradykaushik commented Dec 24, 2020

Adding capability to pause/continue jobs without having to restart the cron scheduler.

Usage

cron := New(WithSeconds())
id, _ cron.AddFunc("?/5 * * * * *", func() { fmt.Println("hello") })
cron.Start()
// wait some time.
cron.Pause(id)
// time to continue work.
cron.Continue(id)
// time to stop cron scheduler.
cron.Stop()

Test Coverage

Test code has been added to test pause/continue feature. The following three scenarios have been tested.

  1. passing invalid entry id to Pause(...).
  2. pausing after single execution, waiting for two scheduling cycles, and then continuing for one more cycle.
  3. pausing and continue jobs when multiple jobs have been scheduled.

With this commit, we now can pause jobs with Pause(id) and then
later continue resume them with Continue(id).

Added test coverage for this feature that tests different scenarios
and also with multiple jobs.
Instead of storing the paused jobs in a map, we're now storing
a bool in Entry.
Note that this means we would be performing a O(n) search on
Pause() and Continue().
added mutex for Entry#Paused.
Also fixed race condition in pause/continue test code.
SamPeng87 pushed a commit to SamPeng87/cron that referenced this pull request May 9, 2022
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