This still has a big problem.  It only checks status when starting the
loop.  If thread 2 starts, and then thread 1 does a row, thread 2 will
do that row too.

On Dec 28, 11:19 pm, Thadeus Burgess <thade...@thadeusb.com> wrote:
> 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 
> > athttp://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.


Reply via email to