On Monday, June 10, 2019 at 9:52:59 PM UTC-7, mostwanted wrote:
>
> I am yet to understand how the scheduler works.
>
> Thanks Dave
>
>
It's simple:  the Scheduler runs as an independent process that watches 
only one thing:  the list of queued tasks.  When it finds that it is time 
to run a queued task, it unqueues it and launches it.  A queued task could 
be one that looks through another table (such as the one used by the web 
requests), and compares the time of the entries with the current time and 
decides which ones are stale, and then marks them inactive or deletes them.

Let's say you have a table where users post discussion topics:  perhaps 
design documents.  The form shown in the browser might include a link to 
the document, the author's name, the project it applies to, and the date 
posted.  You also have a field (hidden in the form) for a status of 
active/inactive/removed.  The removed status is for when the author cancels 
a document, so we won't worry about that during cleanup.

You want to have the table checked every day at 11:59 pm, and all the 
active documents older than 2 weeks to be marked inactive.  You set up the 
Scheduler in your model file, and define a task; that is, you write a 
function to implement the task (more below).  You start the Scheduler from 
a command line (bash shell, or on Windows a cmd window).  You also write a 
small function in one of your controllers that has the 
scheduler.queue_task() call setting the start time and unlimited repeats 
and how often it repeats (every 24*60*60 seconds in this case).  You invoke 
that function (from a browser if you want it to be a web request, from a 
command line using -S if you want it to be only done from the server 
environment.

The function you wrote to implement the task is very simple:  select all 
the documents that are active and are 2 weeks old (post_date.< now() - 
datetime.delta(2 weeks)) and update the status to inactive.

Also note that recent versions of the scheduler allow you to do a recurring 
task with a string that looks like a traditional unix/linux cron entry, 
rather than calculating the number of seconds between runs.

/dps


On Monday, June 10, 2019 at 9:59:04 PM UTC+2, Dave S wrote:
>>
>>
>>
>> On Saturday, June 8, 2019 at 11:47:47 PM UTC-7, mostwanted wrote:
>>>
>>> Is there a way to schedule an automatic deleting of content from 
>>> database on a specified date? I have an application that I want  to delete 
>>> posts when we reach specified dates. If anyone is familiar with this, your 
>>> assistance would be greatly appreciated.
>>>
>>> Regards
>>>
>>> Mostwanted
>>>
>>
>> The other posts  cover how to clean things up when there is a relevant 
>> request around the time that cleaning is desired.
>>
>> If you want the cleaning to be done on a regular basis, the Scheduler is 
>> the weapon of choice.  There's a good description in the book,  at
>> <URL:
>> http://web2py.com/books/default/chapter/29/04/the-core#web2py-Scheduler>
>> and you can find a bunch of posts in the forum archives.
>>
>> /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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/38a599e2-5a67-4093-895e-0816afe6821b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to