I have a bunch of celery workers that need to get single record(row) from the database.
It should only be returned if 60 seconds passed since "last_used" field and as soon as returned, it should update the "last_used" with current time(so other workers that have unlimited retries with 0 delay don't get the same one)
Is it possible to do all of this at db level? I wouldn't have any other source updating this "last_used" field.
Here is how single row looks like.
{"id": "..." "last_used": "2016-06-31 00:37:21.241833", "item": "string"}
I tried:
conn = r.connect(host='localhost', port=28015)
do = r.db('database').table('tb').order_by(index=("last_used")).limit(1).update(
{'last_used': r.now()}
, return_changes=True).run(conn)
And it doesn't work, multiple workers get returned the same row before it is changed.