On Tuesday, February 23, 2016 at 3:11:47 PM UTC-8, Lucas Schreiber wrote: > > Hi there, > while trying to understand how to use the scheduler, i found this post: > https://groups.google.com/forum/#!topic/web2py/VCPZmSc0vLc >
(I think there are some new posts, and reading the Web2Py book is very helpful: <URL:http://web2py.com/books/default/chapter/29/04/the-core#web2py-Scheduler> ) > > In the Post, this code is writen: > db.scheduler_task.insert(function_name='task1', > task_name='task1', > stop_time = now + timedelta(days=90000), > repeats=0, > period=10) > g > Where do i put this code? in the model? I think this was partly answered > in the post, but i dont understand it. can someone explain this to me? > You put it where ever you need it. It can be executed in a Web2Py shell, it can be in a controller that responds to an input, etc. Ooops, I just re-read what you have there ... don't insert directly into the table, call *queue_task()* where ever you need to schedule a task. (Note, there are a LOT of fields in the database table, this post will give you some idea: <URL:https://groups.google.com/d/msg/web2py/V4FftTa0CfE/Yas8cNWUEAAJ> ) I have my *queue_task()* in the model, but it is only executed when I don't already have a task queued. Since model files get loaded on each request, you don't want to be too careless about queuing a task there. Luckily, there is *task_status()*. > > Also, is there a way to let a scheduler run at a time writen in a db once > and then rest until the next time occurs? or is a permanent run every few > seconds checking for certain criteria the better solution? > Check out the other parameters of the queue_task() call (follow the book URL). There's a starttime as well as a period. And just to see if I understood this so far correctly: > the scheduler function is basically a function I write into the model, > offering everything a "normal" function offers, exectued at times i > determine? > Essentially true. There is a request environment, but some fields that only apply to http requests aren't used, and some scheduler-specific fields are used. My code is mostly in a module file, so I have to use an instance of *current* to pass relevant information. HTH /dps -- 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.