for db(status == 'pending').select(): task.update_record(status == 'processing') success = do_long_thing_with(task) fail if success: task.update_record(status = 'done')
This way, records that have a status of processing will not get pulled in by a concurrent thread. -Thadeus On Tue, Dec 29, 2009 at 1:07 AM, toomim <too...@gmail.com> wrote: > What's the best way to use web2py to process a queue of data in a cron > job without race conditions? > > My code basically does this: > > for task in db(status != 'done').select(): > success = do_long_thing_with(task) # takes a long time, might > fail > if success: > task.update_record(status = 'done') > > I launch this every N minutes in a cron job. But if it takes more > than N minutes to run, the cron starts another loop in parallel and > duplicates all calls to do_long_thing_with(task). > > What's the best way to fix this? It seems hard without being able to > manually say where transactions should start with BEGIN. > > -- > > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To post to this group, send email to web...@googlegroups.com. > To unsubscribe from this group, send email to > web2py+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/web2py?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.