Hi

I have no experience with task queues and am thinking to adapt my code from 
both the web2py example of homemade task queues at:

http://web2py.com/books/default/chapter/29/08/emails-and-sms?search=Sending+messages+using+a+background+task#Sending-messages-using-a-background-task

and pythonanywhere longRunningTasks script at:

https://help.pythonanywhere.com/pages/LongRunningTasks/

this page tells the programmer to make sure his code is *resilient to being 
terminated unexpectedly*: what is that mean ? For instance can this code 
extracted from the w2p book be considered resilient :


BOOK EXTRACT:

First, in a model file within our application, we set up a database model 
to store our email queue:

1

2

3

4

5

db.define_table('queue',

    Field('status'),

    Field('email'),

    Field('subject'),

    Field('message'))

>From a controller, we can then enqueue messages to be sent by:

1

2

3

4

db.queue.insert(status='pending',

                email='y...@example.com',

                subject='test',

                message='test')

Next, we need a background processing script that reads the queue and sends 
the emails:

 1

 2

 3

 4

 5

 6

 7

 8

 9

10

11

12

13

## in file /app/private/*mail_queue.py*

import time

while True:

    rows =
                        db(db.queue.status=='pending').select()

    for row in rows:

        if mail.send(to=row.email,

            subject=row.subject,

            message=row.message):

            row.update_record(status='sent')

        else:

           
                        row.update_record(status='failed')

        db.commit()

    time.sleep(60) # check every minute


I didn't investigate too much so far but I might adapt the pythonanywhere 
script to trigger something derived from *mail_queue.py* via python 
*subprocess* module. would this be an orthodox/resilient  way to proceed 
with scheduled tasks ?  

https://docs.python.org/2/library/subprocess.html

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to