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

add locker for distributed scheduling #463

Merged
merged 6 commits into from
May 5, 2023
Merged

Conversation

JohnRoesler
Copy link
Contributor

@JohnRoesler JohnRoesler commented Apr 29, 2023

What does this do?

adds the WithDistributedLocker() method to the scheduler that takes in a Locker allowing for locking jobs when multiple schedulers are running.

The initial implementation is with redis. However, additional implementations may be added here via PR or you may simply implement your own Locker.

Which issue(s) does this PR fix/relate to?

#181
#180

List any changes that modify/break current functionality

Have you included tests for your changes?

yes

testcontainers will soon be officially supporting redis (it's not released, but is available on main) -> https://golang.testcontainers.org/modules/redis/

Super awesome project!

Did you document any new/modified functionality?

  • Updated example_test.go
  • Updated README.md

Notes

This is called out in the function docs for the new method, but I will post it here also:

// WithDistributedLocker prevents the same job from being run more than once
// when multiple schedulers are trying to schedule the same job.
//
// One strategy to reduce splay in the job execution times when using
// intervals (e.g. 1s, 1m, 1h), on each scheduler instance, is to use
// StartAt with time.Now().Round(interval) to start the job at the
// next interval boundary.
//
// Another strategy is to use the Cron or CronWithSeconds methods as they
// use the same behavior described above using StartAt.
//
// NOTE - the Locker will NOT lock jobs using any of the limiting functions:
// SingletonMode, SingletonModeAll or SetMaxConcurrentJobs

@JohnRoesler

This comment was marked as resolved.

@JohnRoesler JohnRoesler merged commit 019f6e1 into main May 5, 2023
4 checks passed
@JohnRoesler JohnRoesler deleted the feature/distributed-locker branch May 5, 2023 02:35
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.

None yet

1 participant