On Friday, March 4, 2016 at 3:25:50 AM UTC-8, Niphlod wrote:
>
> never ever ever call a queue_task() in a model. models gets executed at 
> every request. just queue the task in a "protectedinitialsetup()" 
> controller and use it.
>

Well, that's why I have the status check, but I like your way of doing it.


 

>
> I have a similar approach for 
> rebuilding/reinitializing/requeueing/rechecking all tasks
>
> in a controller (e.g. default.py)
>
> def reinit_sched(protect=None):
>     delete.... bla bla ..... do stuff ... bla bla
>     sched.queue_task(foo)
>     sched.queue_task(bar)
>     etc etc etc
>
>
> you can then easily call it with web2py.py -M -S 
> appname/default/reinit_sched
>
> BTW: it's a little easy trick: every function with arguments can't be 
> called from any request coming in (so it's secured) .. and the -S parameter 
> can take not only the app name, but also the controller and the function to 
> execute...
>
>

Thanks for the clue!

/dps

 

> On Thursday, March 3, 2016 at 8:57:46 PM UTC+1, Dave S wrote:
>>
>>
>>
>> On Thursday, March 3, 2016 at 10:37:30 AM UTC-8, Mohit Jain wrote:
>>>
>>> Hello,
>>>     I would like to know how can one delete rows from a web2py table 
>>> where if a specific field (a timestamp) is older than 24hours? I would like 
>>> this process to keep running in the background in fixed time-intervals 
>>> (every 5 minutes or so) and delete entries from the table where this field 
>>> is older than 24hours from the current time. I know using the Scheduler is 
>>> probably the correct way to go about it but I'm unable to figure out the 
>>> exact code to be written (the documentation has too many options and hence 
>>> a bit confusing). Looking for code samples! :)
>>>
>>>
>> Pretty simple.  You need a model file, say models/scheduler.py
>>
>> import datetime
>>
>> def cleantable():
>>   print "cleantable cleaning the table at %s" % (request.utc_now)
>>   backthen = datetime.strptime(request.utc_now) - datetime.timedelta(h=24)
>>   return backthen.isoformat()       # stdout and the return value will be 
>> in the scheduler_run table, up to the limit in size
>>
>> ts = scheduler.task_status(db.scheduler_task.task_name == 'cleantable')
>> if ts.status not in ["QUEUED", "RUNNING"] :
>>     scheduler.queue_task( "cleantable", start_time = ttime, period = 300, 
>> repeats=0)
>>
>>
>>
>>  If you want a user event to trigger your task, move the queue_task call 
>> to a controller.
>>
>> The limit on stdout contents seems to be 128K
>> <URL:https://groups.google.com/d/topic/web2py/PunI6ffg9xk/discussion>
>>
>>  
>> /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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to