go-quartz icon indicating copy to clipboard operation
go-quartz copied to clipboard

Usage in clustered environment

Open gitkeerthi opened this issue 2 years ago • 6 comments

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)?

gitkeerthi avatar Jan 24 '23 06:01 gitkeerthi

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

reugn avatar Feb 01 '23 11:02 reugn

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.

gedw99 avatar Jun 09 '23 08:06 gedw99

please have planing for support cluster

bingtianyiyan avatar Nov 09 '23 09:11 bingtianyiyan

@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.

reugn avatar Nov 22 '23 14:11 reugn

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.

joint-song avatar Mar 22 '24 04:03 joint-song

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.

reugn avatar Mar 23 '24 12:03 reugn