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

Multi-server lock on jobs #12

Closed
sansmischevia opened this issue Dec 10, 2013 · 6 comments
Closed

Multi-server lock on jobs #12

sansmischevia opened this issue Dec 10, 2013 · 6 comments

Comments

@sansmischevia
Copy link
Contributor

Having agenda be aware of other nodes in the system that connect to the jobs database will be helpful in the scenario you don't want a dedicated batch machine in your environment. This will prevent the same jobs being run twice in the same environment on different machines. (some sort of distributed lock mechanism with mongo?).

@rschmukler
Copy link
Collaborator

Currently, the way I am handling this is with cluster.isMaster();

basically:

if(cluster.isMaster()) {
   require('./lib/jobs');
}

I agree that ultimately we want to make sure that multiple nodes can process from the same database. This is a temporary workaround until we figure out something better.

Any ideas on how we should implement this @sansmischevia ?

@bars3s
Copy link
Contributor

bars3s commented Dec 13, 2013

Hi!
I think this can be done through the lockedAt db field, findAndModify method and agent.define's lockLifetime argument or job.setLockLifetime method. What do you think about it?

@rschmukler
Copy link
Collaborator

I agree for the most part - specifically find and modify.

I don't know if we need lockedAt vs just a boolean locked. I suppose the advantage is if we crash we can have a timeout so we don't corrupt the database.

I think, then, that perhaps defining the lock timeout on the agenda instead of per job would be better. Otherwise we would have to query for a bunch of different locked times, which woulds result in n queries to the database, where n is the number of different lockLifetimes on the job. By doing it per agenda we can do it in 1 query.

@bars3s
Copy link
Contributor

bars3s commented Dec 13, 2013

Ok. I will try to implement it via agenta.define('job name', {lockLifetime: 1000/*ms*/ }, cb), lockedAt db field and findAndModify method.

@rschmukler
Copy link
Collaborator

Implemented in 0.5.0

@sansmischevia
Copy link
Contributor Author

Awesome, thanks @bars3s and @rschmukler! Now to re-write a ton of code with this new addition... agenda had a showstopper due to multi-server issues, but now it's a real lib that rivals quartznet.sourceforge.net

harisvsulaiman pushed a commit to harisvsulaiman/agenda that referenced this issue Nov 8, 2022
Co-authored-by: Aras Abbasi <a.abbasi@cognigy.com>
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

No branches or pull requests

3 participants