Cron and Windows service

145 views
Skip to first unread message

SergeyPo

unread,
Dec 4, 2009, 5:32:48 AM12/4/09
to web2py-users
Hello,

I am having problem with cron. My crontable:

*/5 * * * * root *default/getcaptypes

Controller method 'default/getcaptypes' works fine when you call it
directly. It works fine when called by cron when web2py is running as
console. But it is not working when I start web2py as windows
service.

Options file contains:

extcron = None
nocron = None

Where else should I look?

Sergey

mdipierro

unread,
Dec 4, 2009, 10:52:01 AM12/4/09
to web2py-users
There is a logical problem. the web server and cron are two processes
and therefore they should be threated as two different services or
there should be a mechanism to start and stop them both. Right now the
windows service only handles the web service.

The cron code needs some cleanup because right now it is spread over
multiple modules. I'd rather do the cleanup before adding cron to win
service.

Massimo

SergeyPo

unread,
Dec 4, 2009, 3:52:57 PM12/4/09
to web2py-users
What is the best way to run controller code periodicaly (GET request)?
I need to run it daily, so windows scheduler would be fine, but what
to schedule? Some BAT file or what?

mdipierro

unread,
Dec 4, 2009, 4:03:25 PM12/4/09
to web2py-users
Yes. You can make a bat that runs

python.exe web2py.py -S appname -M -R somescript.py

SergeyPo

unread,
Dec 7, 2009, 1:12:54 AM12/7/09
to web2py-users
For those who is interested, I downloaded curl for windows, wrote bat
file
'curl.exe http://.../appname/controllername/actioname'
and put it into windows scheduler. Web2py Cron service would be much
more elegant.

Brian M

unread,
Dec 8, 2009, 8:18:39 PM12/8/09
to web2py-users
Cron doesn't work when running windows as a service?! :( Well that
just screwed up my plans - I'm working on a reporting app that will
rely fairly heavily on regularly pulling in external data and figured
the built-in cron would handle that.

Is it all forms of cron that don't work with web2py running as a
windows service or just the hard cron? In other words, does soft cron
still work?

~Brian

On Dec 4, 9:52 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> There is a logical problem. the web server andcronare two processes
> and therefore they should be threated as two different services or
> there should be a mechanism to start and stop them both. Right now the
> windows service only handles the web service.
>
> Thecroncode needs some cleanup because right now it is spread over
> multiple modules. I'd rather do the cleanup before addingcronto win
> service.
>
> Massimo
>
> On Dec 4, 4:32 am, SergeyPo <ser...@zarealye.com> wrote:
>
> > Hello,
>
> > I am having problem withcron. My crontable:
>
> > */5   *   *   *   *  root *default/getcaptypes
>
> > Controller method 'default/getcaptypes' works fine when you call it
> > directly. It works fine when called bycronwhen web2py is running as

mdipierro

unread,
Dec 8, 2009, 9:32:02 PM12/8/09
to web2py-users
How important is this to you? It should not be too difficult to add
it. It is just that I think cron and regular web2py should be
considered two different services.

Wes James

unread,
Dec 8, 2009, 9:55:06 PM12/8/09
to web...@googlegroups.com
I've used this:

http://www.kalab.com/freeware/cron/cron.htm

in my labs. It also mentions an update to this called pycron. Maybe
you could use this on the side??

-wes
> --
>
> You received this message because you are subscribed to the Google Groups "web2py-users" group.
> To post to this group, send email to web...@googlegroups.com.
> To unsubscribe from this group, send email to web2py+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/web2py?hl=en.
>
>
>

Brian M

unread,
Dec 8, 2009, 10:38:28 PM12/8/09
to web2py-users
It certainly would be nice to have cron working under the windows
service. I could use Windows scheduled tasks and curl, but was
thinking that it would be nice to have the whole thing controlled/
managed by web2py.

I don't really have any objection to the web2py cron being in its own
service.

~Brian

David Mitchell

unread,
Dec 8, 2009, 10:52:52 PM12/8/09
to web...@googlegroups.com
I've used pycron in the past and found it extremely reliable.  Haven't tried it with web2py, but it's probably worth a look

2009/12/9 Brian M <bmer...@gmail.com>

Brian M

unread,
Dec 9, 2009, 12:01:51 AM12/9/09
to web2py-users
OK, so even though cron won't run with web2py as a Windows service,
triggering it with "python web2py.py -C" from Task Scheduler or pycron
should still work - correct? Assuming of course that if you say have
the external scheduler set for every 5 minutes the web2py crontab also
has everything at intervals divisible by 5. It seems that using the
two in tandem might be easiest since then you don't have to also
define a bunch of curl calls/make batch files.

On Dec 8, 9:52 pm, David Mitchell <monch1...@gmail.com> wrote:
> I've used pycron in the past and found it extremely reliable.  Haven't tried
> it with web2py, but it's probably worth a look
>
> 2009/12/9 Brian M <bmere...@gmail.com>
> > web2py+un...@googlegroups.com<web2py%2Bunsu...@googlegroups.com>
> > .

SergeyPo

unread,
Dec 9, 2009, 12:36:27 AM12/9/09
to web2py-users
Calling "python web2py.py -C" from Task Scheduler will open console
window, and this is something I don't want on production server. I
don't see any good in calling "python web2py.py -C" from Task
Scheduler because python won't stop after a script finished, so you
will have a mess of two schedulers: Windows and web2py -C.

Having a cron inside web2py is definitely a great feature, and if it
runs properly in Windows as separate service (web2py -W install -C ?)
adds much value to the framework.

mdipierro

unread,
Dec 9, 2009, 3:46:18 AM12/9/09
to web2py-users
I would take a patch to do it. I do not use windows much so it would
be hard for me to test it.

Nicol van der Merwe

unread,
Dec 9, 2009, 6:55:48 AM12/9/09
to web...@googlegroups.com
I am in the same boat as you, Brian. I just started a project hoping this is possible.

I would try and submit a patch for this but I have *no* time at all as I am swamped with work :(.

--

You received this message because you are subscribed to the Google Groups "web2py-users" group.
To post to this group, send email to web...@googlegroups.com.
To unsubscribe from this group, send email to web2py+un...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/web2py?hl=en.





--

Jonathan Swift  - "May you live every day of your life."

mdipierro

unread,
Dec 9, 2009, 11:55:01 AM12/9/09
to web2py-users
I will try work on this later today.
> > web2py+un...@googlegroups.com<web2py%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/web2py?hl=en.
>
> --
>
> Jonathan Swift<http://www.brainyquote.com/quotes/authors/j/jonathan_swift.html>

Brian M

unread,
Dec 9, 2009, 4:43:59 PM12/9/09
to web2py-users
Massimo - I'm willing to help do some testing since I'm stuck on
Windows.

SergeyPo - isn't using unix cron and "python web2py.py -C -D
1" (external cron) the recommended method when using FastCGI or WSGI?
(http://web2py.com/examples/default/cron) Why would doing essentially
the same thing with the Windows scheduler be any different? I don't
think python is going to stay running once the cron run is done.

~Brian

mdipierro

unread,
Dec 11, 2009, 12:12:20 PM12/11/09
to web2py-users
Please do the following check.
in gluon/widget.py there

if cron and not options.nocron:
print 'Starting cron...'
contrib.cron.crontype = 'hard'
cron = contrib.cron.hardcron()
cron.start()

is this code executed when you run with -W? What are the values of
cron and options.nocron?



On Dec 9, 3:43 pm, Brian M <bmere...@gmail.com> wrote:
> Massimo - I'm willing to help do some testing since I'm stuck on
> Windows.
>
> SergeyPo - isn't using unixcronand "python web2py.py -C -D
> 1" (externalcron) the recommended method when using FastCGI or WSGI?
> (http://web2py.com/examples/default/cron) Why would doing essentially
> the same thing with the Windows scheduler be any different? I don't
> think python is going to stay running once thecronrun is done.
>
> ~Brian
>
> On Dec 9, 10:55 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > I will try work on this later today.
>
> > On Dec 9, 5:55 am, Nicol van der Merwe <aspersie...@gmail.com> wrote:
>
> > > I am in the same boat as you, Brian. I just started a project hoping this is
> > > possible.
>
> > > I would try and submit a patch for this but I have *no* time at all as I am
> > > swamped with work :(.
>
> > > On Wed, Dec 9, 2009 at 3:18 AM, Brian M <bmere...@gmail.com> wrote:
> > > >Crondoesn't work when running windows as a service?! :( Well that
> > > > just screwed up my plans - I'm working on a reporting app that will
> > > > rely fairly heavily on regularly pulling in external data and figured
> > > > the built-incronwould handle that.
>
> > > > Is it all forms ofcronthat don't work with web2py running as a

Brian M

unread,
Dec 11, 2009, 10:39:10 PM12/11/09
to web2py-users
Massimo - here are my test results

I modified gluon/widget.py to include the following

# ## Starts cron daemon

if cron and not options.nocron:
print 'Starting cron...'
print 'cron = '+str(cron)
print 'options.nocron = '+str(options.nocron)
contrib.cron.crontype = 'hard'
cron = contrib.cron.hardcron()
cron.start()

When I run python web2py.py -W start I get:

python web2py.py -W start
default applications appear to be installed already
web2py Enterprise Web Framework
Created by Massimo Di Pierro, Copyright 2007-2009
Version 1.73.1 (2009-12-07 07:55:13)
Database drivers available: SQLite3, PostgreSQL, MSSQL/DB2
Starting cron...
cron = True
options.nocron = False
Starting service web2py

I have setup a cron task to simply insert the current datetime into a
database table once a minute (hey I'm impatient).
Results:
web2py server - not running as service: Cron works as expected
web2py server - running as a service: Cron tasks do NOT work
python web2py.py -C -D 1 >> cron_log.log : Cron works as expected

This is on WindowsXP with current trunk (rev 11) from the google hg
repo.

~Brian

On Dec 11, 11:12 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> Please do the following check.
> in gluon/widget.py there
>
>     ifcronand not options.nocron:
>         print 'Startingcron...'
>         contrib.cron.crontype = 'hard'
>        cron= contrib.cron.hardcron()
>        cron.start()
>
> is this code executed when you run with -W? What are the values ofcronand options.nocron?
>
> On Dec 9, 3:43 pm, Brian M <bmere...@gmail.com> wrote:
>
> > Massimo - I'm willing to help do some testing since I'm stuck on
> >Windows.
>
> > SergeyPo - isn't using unixcronand "python web2py.py -C -D
> > 1" (externalcron) the recommended method when using FastCGI or WSGI?
> > (http://web2py.com/examples/default/cron) Why would doing essentially
> > the same thing with theWindowsscheduler be any different? I don't
> > think python is going to stay running once thecronrun is done.
>
> > ~Brian
>
> > On Dec 9, 10:55 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > I will try work on this later today.
>
> > > On Dec 9, 5:55 am, Nicol van der Merwe <aspersie...@gmail.com> wrote:
>
> > > > I am in the same boat as you, Brian. I just started a project hoping this is
> > > > possible.
>
> > > > I would try and submit a patch for this but I have *no* time at all as I am
> > > > swamped with work :(.
>
> > > > On Wed, Dec 9, 2009 at 3:18 AM, Brian M <bmere...@gmail.com> wrote:
> > > > >Crondoesn't work when runningwindowsas a service?! :( Well that
> > > > > just screwed up my plans - I'm working on a reporting app that will
> > > > > rely fairly heavily on regularly pulling in external data and figured
> > > > > the built-incronwould handle that.
>
> > > > > Is it all forms ofcronthat don't work with web2py running as a
> > > > >windowsservice or just the hardcron? In other words, does softcron
> > > > > still work?
>
> > > > > ~Brian
>
> > > > > On Dec 4, 9:52 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> > > > > > There is a logical problem. the web server andcronare two processes
> > > > > > and therefore they should be threated as two different services or
> > > > > > there should be a mechanism to start and stop them both. Right now the
> > > > > >windowsservice only handles the web service.
Reply all
Reply to author
Forward
0 new messages