Scheduled execution of command inside CP

2 views
Skip to first unread message

morellik

unread,
May 12, 2008, 9:24:17 AM5/12/08
to cherrypy-users
Dear all,

is it possible to execute some commands each, e.g., two days or other
values during the CP3 application life?

I wrote an application to permit to some users to share files, but I
want that each two days the files will be removed. I can write an
application to run under cron, but I prefer, if it's possible, to do
under CP.

Thanks
Enrico

Christian Wyglendowski

unread,
May 12, 2008, 9:28:34 AM5/12/08
to cherryp...@googlegroups.com
On Mon, May 12, 2008 at 9:24 AM, morellik <enrico....@gmail.com> wrote:
> is it possible to execute some commands each, e.g., two days or other
> values during the CP3 application life?

Robert has a great module for this:

http://www.aminus.net/wiki/Recur

I've used it before and highly recommend it.

Christian
http://www.dowski.com

Eddie Corns

unread,
May 12, 2008, 9:34:21 AM5/12/08
to cherryp...@googlegroups.com
Date: Mon, 12 May 2008 06:24:17 -0700 (PDT)
From: morellik <enrico....@gmail.com>
X-Spam-Level:


Dear all,

You could create a seperate thread that reads a Queue() for actions with a
timeout on the Q.get() set for when the next action is due to be performed.

Or you could be lazy like I was and create a normal URL for CP to perform the
expiry checks and have an incredibly simple script under cron that just does a
GET on that URL.

Eddie

--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

morellik

unread,
May 12, 2008, 10:56:44 AM5/12/08
to cherrypy-users


On May 12, 3:28 pm, "Christian Wyglendowski" <christ...@dowski.com>
wrote:
> On Mon, May 12, 2008 at 9:24 AM, morellik <enrico.more...@gmail.com> wrote:
> >  is it possible to execute some commands each, e.g., two days or other
> >  values during the CP3 application life?
>
> Robert has a great module for this:
>
> http://www.aminus.net/wiki/Recur
>
> I've used it before and highly recommend it.
>
> Christianhttp://www.dowski.com

Thanks, seems what I need.

To work with CP have I to subclass Worker and use its work methods?

Enrico

morellik

unread,
May 12, 2008, 10:57:44 AM5/12/08
to cherrypy-users


On May 12, 3:34 pm, Eddie Corns <E.Co...@ed.ac.uk> wrote:
>    Date: Mon, 12 May 2008 06:24:17 -0700 (PDT)
>    From: morellik <enrico.more...@gmail.com>
>    X-Spam-Level:
>
>    Dear all,
>
>    is it possible to execute some commands each, e.g., two days or other
>    values during the CP3 application life?
>
>    I wrote an application to permit to some users to share files, but I
>    want that each two days the files will be removed. I can write an
>    application to run under cron, but I prefer, if it's possible, to do
>    under CP.
>
> You could create a seperate thread that reads a Queue() for actions with a
> timeout on the Q.get() set for when the next action is due to be performed.
>
> Or you could be lazy like I was and create a normal URL for CP to perform the
> expiry checks and have an incredibly simple script under cron that just does a
> GET on that URL.
>
> Eddie

Thanks also to you.
Can you give me the script?

Enrico

Eddie Corns

unread,
May 12, 2008, 11:17:37 AM5/12/08
to cherryp...@googlegroups.com
Date: Mon, 12 May 2008 07:57:44 -0700 (PDT)
From: morellik <enrico....@gmail.com>

On May 12, 3:34 pm, Eddie Corns <E.Co...@ed.ac.uk> wrote:


>    Date: Mon, 12 May 2008 06:24:17 -0700 (PDT)
>    From: morellik <enrico.more...@gmail.com>

>    Dear all,
>
>    is it possible to execute some commands each, e.g., two days or other
>    values during the CP3 application life?
>
>    I wrote an application to permit to some users to share files, but I
>    want that each two days the files will be removed. I can write an
>    application to run under cron, but I prefer, if it's possible, to do
>    under CP.
>
> You could create a seperate thread that reads a Queue() for actions with a
> timeout on the Q.get() set for when the next action is due to be performed.
>
> Or you could be lazy like I was and create a normal URL for CP to perform the
> expiry checks and have an incredibly simple script under cron that just does a
> GET on that URL.
>
> Eddie

Thanks also to you.
Can you give me the script?

Enrico

I don't have it as a stand-alone script but we're talking about something
like:

import urllib
f = urllib.urlopen('http:<your-base-url>/expire')
status = f.read()
f.close()

I usually pass back a simple string like 'OK' or 'FAIL' which goes into
status.

A command line script like curl or wget would do just as well.

Call it from cron every hour say.

The CP Root object has an exposed 'expire' method which looks for any old
files to delete and returns 'OK' or 'FAIL'.

HTH,

Reply all
Reply to author
Forward
0 new messages