On Nov 6, 2011, at 9:03 AM, Wei-Ning Huang wrote:

> 
> Can I ask you more about the queue operations you talked about?
> currently I'm using like this:
> 
> results = db.query(Table).filter(condition & (Table.status != 
> 'QUEUED')).with_lockmode('update')
> ids = [result.id for result in results]
> db.query(Table).filter(Table.id.in_(ids)).delete()
> return results
> 
> if this correct? I'm not sure if I can delete the rows selected with lockmode 
> 'update'.
> Thanks for answering!

right...I usually just do an UPDATE, then when the job completes it's updated 
again as COMPLETED.   The rows remain in the database as a record of the job 
proceeding.      A periodic task can delete those rows that are in 
COMPLETED/FAILED status which are older than X days.

Alternatively, the job itself can DELETE its own row later.   The key is to 
emit an UPDATE first so that the status flag prevents the rows from being 
grabbed by another process.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to