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 web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.