zer0stimulus
zer0stimulus

Reputation: 23606

Django MySql Row Locking

I'm looking to use a Model, backed by a mysql table, as a job queue, shared among concurrent processes. I'm trying to avoid a situation where 2 processes execute the same job. The first thought would be to add a dirty flag to a row (job), that's marked when a process is executing that job. But then we have the classic problem where checking the dirty bit is a distinct operation from writing the dirty bit. How could I make the 2 operations atomic?

Ideally, each row would have a spinlock, which can be locked by a process updating the row, and prevents other processes for accessing the row. Does Django support this concept?

Upvotes: 0

Views: 829

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798626

QuerySet.select_for_update() is in the development version. On stable releases you'll need to use raw queries yourself.

Upvotes: 1

Related Questions