On Monday, April 24, 2017 at 12:40:00 PM UTC-7, Anthony wrote:
>
> Yeah, don't put the queue_task code in the model, as it will get executed 
> every time the model is executed. If you just need to set up the task once, 
> you can do so by directly inserting a record in the scheduler_task table 
> via appadmin or by calling queue_task() in a web2py shell. Or you could 
> create a special restricted-access controller function and visit its URL 
> just once to schedule the task.
>


An example of the latter approach is at 
<URL:https://groups.google.com/d/msg/web2py-developers/cI7R-9hex7k/PfTsGodYEwAJ>

The pull request has been merged, and should be visible on the web2py 
website when the next release is out of the gate.

/dps

 

> On Monday, April 24, 2017 at 3:36:53 PM UTC-4, Kenneth Ban wrote:
>>
>> Hi,
>>
>> I'm trying to set up the web2py scheduler to run an hourly task and put 
>> the following code as scheduler.py in the models directory:
>>
>> from gluon.scheduler import Scheduler
>>
>>
>> def log():
>>     
>>     logging.warning('is when this event was logged.')
>>
>>
>> import logging
>>
>>
>> logger = logging.getLogger("web2py.app.welcome")
>>
>> logger.setLevel(logging.DEBUG)
>>     
>>     myscheduler = Scheduler(db,tasks=dict(log=log))
>>
>> myscheduler.queue_task('log',period=3600,repeats=0,immediate=True)
>>
>> However I find that each time I visit the website, it schedules a new 
>> task, resulting in multiple tasks of the same nature (i.e. period=3600, 
>> repeats=0).
>>
>> How do I run the set up once so that I will only get a single repeating 
>> task queued in the web2py scheduler.
>>
>> Thanks in advance for any help!
>>
>> Cheers,
>> Kenneth
>>  
>>
>>
>>

-- 
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