This is what I would do:

db.define_table('queue',Field('status'),Field('descr'))

In actions

db.queue.insert(status='PENDING',descr='whatever')

In your own scrips that you can run via CRON or via background process

while True:
    tasks = db(db.queue.status=='PENDING').select(limitby=(0,10)).first
()
    if task:
        task.update_record(status='PROCESSING')
        db.commit()
        try:
             #process task
             task.update_record(status='COMPLETED')
        except:
             task.update_record(status='FAILED')
        db.commit()
    else:
        sleep(10) # retry in 10 seconds



On Jan 3, 7:28 am, Richard <richar...@gmail.com> wrote:
> I haven't implemented this yet, but my plan on Linux to keep a
> background process running is:
>
> - Define a task table, which is checked on every request
> - If the task table is empty then start the background task with
> subprocess and store the pid in the task table
> - If the task table has an entry but its pid is not active (not in /
> proc) then restart the background task and update the pid
> - Else the task is running fine
>
> Perhaps you could adapt that to your needs, assuming you are using
> Linux.
>
> Richard
>
> On Dec 30 2009, 3:26 pm, Auden RovelleQuartz <oves....@gmail.com>
> wrote:
>
> > any simple example on how to create a persistent background process
> > that runs continuously on the server side no matter what user signs in
> > or out, and no matter how many concurrent users are on the system?
>
> > Here are a couple of examples:
>
> > when a user performs an "event", it kicks off a server side process
> > that continues executing even when that user signs off.
>
> > when a user performs an "event", then after a set period of time (say
> > two days) then an email is automatically sent to a specified e-mail
> > address that happens even if the user that triggers the event no
> > longer has an active session on the server side.
>
> > I am attempting to build an auction application in the web2py
> > framework and would be interested in learning a tecqnique of starting
> > (and stopping) persistent server-side background processes.
>
> > Much thanks
>
>

--

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