reugn / go-quartz

Minimalist and zero-dependency scheduling library for Go
https://pkg.go.dev/github.com/reugn/go-quartz/quartz
MIT License
1.8k stars 85 forks source link

Usage in clustered environment #45

Closed gitkeerthi closed 6 months ago

gitkeerthi commented 1 year ago

How do you use this in a clustered environment where more than one instance of the scheduler might exist? Is there a feature similar to quartz cluster mode (https://flylib.com/books/en/2.65.1/how_clustering_works_in_quartz.html)?

reugn commented 1 year ago

@gitkeerthi Clustering is not supported within the library, but a persistent job store can be implemented independently.

gedw99 commented 1 year ago

Maybe a simple global system like etcd , kine or nats would be a simple global locking store .

let’s use NATS because it has subscriptions which is handy.

so the 3 events are:

When a job starts it registers with NATS , so no other servers take the job.

on job start , check with NATS and if not in nats, run the job.

On job finish , unregister with nats

—-

you can embed nats servers in your project too which is handy . Nats will automatically do leader election so if a server fails and new leader is automatically chosen . It also has gracefull upgrades using lamb duck mode. So this means you don’t have to run a “special jobs locking server” but can just include it in your golang project

—-

I don’t know if Quartz has job lease time and retries , but the above can probably work with the above design .

Btw thos already exists and uses nats for job locking as well as other aspects :

https://github.com/choria-io/asyncjobs

it also has a schedular: https://choria-io.github.io/asyncjobs/overview/scheduled-tasks/

in their code it’s used cron golang module.

maybe there is opportunity to use Quarz but not sure yet.

bingtianyiyan commented 1 year ago

please have planing for support cluster

reugn commented 1 year ago

@gitkeerthi, @gedw99, @bingtianyiyan I've opened a pull request (#80) to support custom job queue implementation that can provide persistent storage and state sharing for jobs. Please review, and let me know if this satisfies your requirement.

joint-song commented 8 months ago

You mean that we can create multiple instances of Scheduler, and these schedulers can have respective Persistent Queue(We can surely set a field in RDBMS table to seperate each queue jobs)? Each scheduler has own timer, event-loop etc. Please correct me if I misunderstand this solution.

reugn commented 8 months ago

By implementing a shared persistence layer, you can enable multiple scheduler instances to retrieve and process jobs. This architecture supports high availability (HA) scenarios and facilitates scalability when job processing becomes highly competitive.