Reasons not to use database locking for cron?

Reasons not to use database locking for cron?

by Michael Aherne -
Number of replies: 1
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Are there any good reasons to avoid db_record_lock_factory in favour of file_lock_factory for cron job locking? (I'm having trouble working this out from the documentation.)

I'd assume that the performance will be a lot worse, but the lock API documentation explicitly says "locking is not meant to be fast", so presumably this doesn't matter too much.

The reason I'm asking is that we're (very occasionally) seeing cron jobs running twice at the same time and are concerned it might be something to do with file locking. As far as we can see, file locking is generally sound on our setup, but we might prefer to use database locking as it seems simpler and potentially more stable than relying on file locking across a cluster.

Average of ratings: -
In reply to Michael Aherne

Re: Reasons not to use database locking for cron?

by Darko Miletić -

That really depends on your setup. The rule of thumb would be - if you have just one server instance for web and another for database setup cron on your web node. If you have multiple web servers behind load balancer for one moodle instance than add another server that will not be accessible from outside and will host cron process. That way you are sure that one and only one cron instance is run for particular setup.