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