I am running Django on several websites connected to a shared database server. The database contains a simple table of pending jobs. eg.
class Job(models.Model): name = models.CharField(max_length=255, null=False, help_text='task to do') worker = models.CharField(max_length=255, null=True, help_text='globally unique host name')
How can I use Django ORM to request a pending job (where the worker is null) and set the name of the worker atom atomically, so that no two Django processes accidentally capture the same job (i.e. avoid the race condition)?
Ideally, I just want to wrap on request / update inside a table lock, but Django ORM doesn't seem to have a built-in function.
Cerin source share