Thank you very much Tim, excelent info. I will use web2py's Scheduler, because it will be easy to write some code and let the user change the configuration from the webapp.
However, I have one last concern about system resources on production. As I'm going to use this in production, my webapp will be installed multiple times (that is, multiple virtual hosts, each one running an instance of web2py). Therefor, accordingly to the documentation, I will have to run the scheduler as a linux service (http://web2py.com/books/default/chapter/29/13/deployment-recipes#Start-the-scheduler-as-a-Linux-service--upstart-). In my case, I will be running a service for each instance of web2py running, but as I said, each scheduler will correspond to the sending of a daily newsletter, that is, each scheduler will execute only one task per day. Therefor my doubt: ¿does the scheduler consume much resources being "idle" waiting for tasks to be queued? In the other hand, after reading web2py's scheduler documentation, I found out that, if I want to schedule a task that runs every day at a certain time, I would have to queue the task in this way: scheduler.queue_task( send_newsletter, # the function that sends the newsletter start_time=first_execution, # first_execution would be, for example, tomorrow at 8am period=86400, # one day, expressed in seconds repeats = 0 # unlimited repeats ) Is that ok? If I do it this way, should I increase the heartbeat to 60 seconds or more? That is, taking into account that the scheduler will only have to run one task per day. El martes, 23 de diciembre de 2014 17:07:28 UTC-3, Tim Richardson escribió: > > I use the scheduler for activities that run daily to some that run every > 15 minutes. > It doesn't do day-of-the-week yet so you would need to check for that in > your daily code. I for example have an app which sends SMS every hour, but > the task checks that it is in office hours before doing any work. > The scheduler is a good tool, and once you've learnt it, you have a > cross-platform tool at your disposal. It's easy to manipulate in web2py > since there is an API (which basically updates records; this will make it > easy to meet your requirement that the user chooses when to start the > task). It has a simple logging approach (output is saved in tables) and it > scales to multiple workers easily. > > I think the references to "cron must die" refer to a web2py deprecated > feature unfortunately named cron; don't confuse it with the system cron > built in your server OS. > Therefore you may decide to use cron. In which case... > You can run web2py scripts in the context of your application using the > web2py command line > python web2py -S {app} -R <{path_prefix}/mymodule.py > (see documentation in the book; the -S option needs to be used as well). > > You could for example put your code in a module, and have code in the > global context (if __name__ == "__main__" ...) which will be run when you > execute the command line. > > > > > > > > > On Wednesday, 24 December 2014 01:18:09 UTC+11, Lisandro wrote: >> >> I've been reading about web2py's cron and sheduler ([1] and [2]) >> Also, I've read a post where Massimo says "Please use the scheduler, not >> cron. Cron must die." [3] >> >> Now I'm creating a web2py app and I want the user to be able to configure >> a daily background task. The task consist in sending a newsletter to >> subscribers. The task doesn't take too much time to complete (because the >> app doesn't use smpt; it connects to an API so the sending is handled by an >> external service). So the task only makes some query to the database, >> connect to the API, give the order to send, and disconnect. >> The thing is: I want the user to be able to configure the time that the >> newsletter is sent. For example, the user may configure the sending of the >> newsletter from monday to friday at 8am, but not saturdays o sundays. >> >> In this scenario, I first thought that cron would be the way to go. >> However I read that Massimo's comment ("cron must die") so I don't know >> what to use. >> I find that scheduler is very complete and robust, but I don't know if >> it's the best option for this case, considering that the task runs in very >> little time and only once a day. I'm worried about resource consumption, >> because the same app is installed multiple times on production, serving >> multiple websites, so there would be multiple workers running on background >> (maybe idle workers, however they would take some memory space I guess). >> >> Any tip or comments? Does anyone dealed with something similar? I want to >> remark the idea that the user must be able to change configuration about >> the scheduled task. >> Thanks in advance! >> >> [1] >> http://web2py.com/books/default/chapter/29/04/the-core#Running-tasks-in-the-background >> [2] >> http://web2py.com/books/default/chapter/29/13/deployment-recipes#Start-the-scheduler-as-a-Linux-service--upstart- >> [3] >> https://groups.google.com/forum/#!searchin/web2py/cron$20must$20die/web2py/qW_ODOj3nMM/8hbZ6etJsvcJ >> >> -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.

