I just tried trunk cron on Linux and it does NOT seem to be working.
Oddly, debugging is showing "DEBUG:root:WEB2PY CRON Call retruned
success:" but it does not appear the tasks are actually running. I've
got a "cron_test" app setup with controller functions to write a
message to both a file and sqlite database - it works correctly with
trunk on Windows and with stable on linux, but it doesn't work with
trunk on Linux.
controller "default" contains (partial set, they all follow the same
format)
---------------------------------------------
def on_five():
import os.path
from datetime import datetime
file_path = os.path.join(request.folder,'cron_test.log')
print file_path
f = open(file_path,'a')
message = "CRON - 5Min interval web2py application
"+request.application+" run at "+str(datetime.now())+"\n"
f.write(message)
db.cron.insert(what=message)
db.commit()
return dict(message = message)
def on_ten():
import os.path
from datetime import datetime
file_path = os.path.join(request.folder,'cron_test.log')
f = open(file_path,'a')
message = "CRON - 10Min interval web2py application
"+request.application+" run at "+str(datetime.now())+"\n"
f.write(message)
db.cron.insert(what=message)
db.commit()
return dict(message = message)
db.py contains:
---------------------------------
from datetime import datetime
db.define_table('cron',
Field('run_datetime','datetime',notnull=True, default=datetime.now
()),
Field('run_date','date',notnull=True, default=datetime.now().date
()),
Field('run_time','time',notnull=True, default=datetime.now().time
()),
Field('what','string',notnull=True))
crontab contains (partial contents)
------------------------
#crontab
@reboot root *default/on_reboot
0-59/5 * * * * root *default/on_five
>>cron_runs.log
0-59/10 * * * * root *default/on_ten
>>cron_runs.log
Looks like we need to back up a bit. AchipA I'll let you take a shot
for a while. Let me know if you'd like help testing.
~Brian M
On Jan 31, 8:12 pm, mdipierro <[email protected]> wrote:
> I can stop making changes. Please make sure your changes apply to
> latest trunk.
>
> On Jan 31, 5:19 pm, AchipA <[email protected]> wrote:
>
>
>
> > I'm also workin on refactoring a few things in cron, let's not trip
> > over each other :) I see people have been busy with my code so there
> > are more things to check than I initially thought, but I'm still on
> > track. I also plan on including a test module which will make
> > regression tests easier.
>
> > On Jan 31, 6:24 pm, Brian M <[email protected]> wrote:
>
> > > Massimo,
>
> > > In trunk your check for Windows should be
>
> > > platform.system() == 'Windows'
>
> > > and not
>
> > > platform.systems() = 'Windows'
>
> > > You've got an extra s in there. I don't know that you need to disable
> > > it for windows as a whole or just for the binary distro of web2py. I
> > > have to do more testing.
>
> > > Also, I think in your rewrites of cron you may have taken out too much
> > > of the logic behind when to run a task, it appears that you are only
> > > checking the minute and not the hour, day of week, etc.
>
> > > ~Brian
>
> > > On Jan 30, 9:51 pm, mdipierro <[email protected]> wrote:
>
> > > > fantastic. I am uploading the fix to trunk. Please make sure I did not
> > > > mess it up.
> > > > I very much appreciate your help.
>
> > > > On Jan 30, 8:46 pm, Brian M <[email protected]> wrote:
>
> > > > > Massimo,
>
> > > > > The problem is in def parsecronline() there needs to be an extra elif
> > > > > clause to deal with that -1 minute value for @reboot tasks.
>
> > > > > for (s, id) in zip(params[:5], ['min', 'hr', 'dom', 'mon', 'dow']):
>
> > > > > if not s in [None, '*']:
> > > > > task[id] = []
> > > > > vals = s.split(',')
> > > > > for val in vals:
> > > > > print val
> > > > > if val.find('/') > -1:
> > > > > task[id] += rangetolist(val, id)
> > > > > elif val.isdigit():
> > > > > task[id].append(int(val))
> > > > > elif val == "-1":
> > > > > #...@reboot line
> > > > > task[id].append(int(-1))
> > > > > task['user'] = params[5]
> > > > > task['cmd'] = params[6]
> > > > > return task
>
> > > > > unfortunately, -1 fails the isdigit() test and therefore instead of
> > > > > min containing [-1] it contains nothing [].
>
> > > > > I'm going to see if I can't figure out the windows space in path issue
> > > > > next.
>
> > > > > ~Brian
>
> > > > > On Jan 30, 8:11 pm, mdipierro <[email protected]> wrote:
>
> > > > > > Hi Brian,
>
> > > > > > can you help me debug this.
>
> > > > > > In gluon/contrib/cron.py there is a line in function crondance:
>
> > > > > > elif not startup and task.get('min',[])==[-1]:
> > > > > > continue
>
> > > > > > @reboot startup is supposed to be true the first time only and
> > > > > > task.get
> > > > > > ('min',[]) is supposed to be ==[-1].
>
> > > > > > Is this not the case? Can you add a print statement before that line
> > > > > > to print statup and task?
>
> > > > > > massimo
>
> > > > > > On Jan 30, 7:52 pm, Brian M <[email protected]> wrote:
>
> > > > > > > OK, just pulled latest trunk out of the google code hg repo and
> > > > > > > @reboot seems to be working on Win7 - actually it's working a bit
> > > > > > > too
> > > > > > > good. Not only does it run on web2py startup, but it CONTINUES to
> > > > > > > run
> > > > > > > once a minute from then on!
>
> > > > > > > I did notice that I had the @reboot crontab syntax wrong
> > > > > > > earlier. It
> > > > > > > is supposed to be just
>
> > > > > > > @reboot root *mycontroller/myfunction
>
> > > > > > > and NOT
>
> > > > > > > �...@reboot * * * * root
> > > > > > > *mycontroller/myfunction
>
> > > > > > > as I had tried before. (BTW, the incorrect syntax is shown at the
> > > > > > > bottom of the docs page -http://web2py.com/examples/default/cron.
> > > > > > > Though the correct form is towards the top of the same page). If
> > > > > > > you
> > > > > > > use that syntax, you get an error message at the console:
> > > > > > > invalid application name: testing/ * * *default/
> > > > > > > on_reboot.
>
> > > > > > > ~Brian
>
> > > > > > > On Jan 30, 5:39 pm, Brian M <[email protected]> wrote:
>
> > > > > > > > Well on my Win7 setup with source distribution of web2py I can
> > > > > > > > confirm
> > > > > > > > that @reboot cron lines do not run when I start up web2py. The
> > > > > > > > same
> > > > > > > > cron line with a normal time declaration does run just fine.
>
> > > > > > > > #...@reboot does not run
> > > > > > > > @reboot * * * * root *reboot/on_reboot
> > > > > > > > #But with normal time syntax runs just fine
> > > > > > > > 0-59/5 * * * * root *reboot/on_reboot
>
> > > > > > > > As far as spaces in file path names affecting things, I'd need
> > > > > > > > more
> > > > > > > > specific information about what is in people's crontab files.
> > > > > > > > When I
> > > > > > > > was trying to test @reboot I purposely stuck web2py in a path
> > > > > > > > that
> > > > > > > > contained spaces and didn't seem to have any problems. Normally
> > > > > > > > within
> > > > > > > > python scripts I use os.path.join() to build up my file paths
> > > > > > > > so that
> > > > > > > > I don't have to worry about the slashes - os.path.join('C:\',
> > > > > > > > 'Documents and Settings', 'Username', 'My Documents', 'folder',
> > > > > > > > 'sub
> > > > > > > > folder', 'file.txt') works just fine.
>
> > > > > > > > Also in my crontab, I could execute a non-web2py python script
> > > > > > > > with
>
> > > > > > > > 0-59/2 * * * * root python
> > > > > > > > "C:\Users\Brian\Documents\some project
> > > > > > > > \scripts\some_script.py" >> cron.log
>
> > > > > > > > On Windows you do need to add the python executable to your
> > > > > > > > path if
> > > > > > > > you don't want to always have to type C:\Python26\python.exe
> > > > > > > > script.py
> > > > > > > > - for some reason the windows python installer doesn't do it
> > > > > > > > automatically. If you don't know already, here's how...
>
> > > > > > > > Win7:
> > > > > > > > Right click on "My Computer" and choose "Properties"
> > > > > > > > On the left side click the "Advanced System Settings" link.
> > > > > > > > Go to the "Advanced" tab
> > > > > > > > Click on the "Environment Variables" button at the bottom.
> > > > > > > > In the "System Variables" section (the bottom one), scroll down
> > > > > > > > to
> > > > > > > > "Path" and click once to highlight. (If you want it only for
> > > > > > > > your
> > > > > > > > use, add it to the user variables. You'll need to add a new
> > > > > > > > "Path"
> > > > > > > > variable)
> > > > > > > > Click the "Edit..." button.
> > > > > > > > In the "Variable value" field, add ";C:\Python26\" on to the
> > > > > > > > end -
> > > > > > > > without the quotes, the semi-colon is the separator between the
> > > > > > > > multiple entries. (If you're using Python 2.5 then use
> > > > > > > > C:\Python25)
> > > > > > > > Click "OK" three times to get rid of all the windows.
>
> > > > > > > > WinXP:
> > > > > > > > Right click on "My Computer" and choose "Properties"
> > > > > > > > Go to the "Advanced" tab.
> > > > > > > > Follow the rest of the instructions above.
> > > > > > > > Same as above
>
> > > > > > > > ~Brian
>
> > > > > > > > On Jan 30, 4:55 pm, mdipierro <[email protected]> wrote:
>
> > > > > > > > > I replace the Popen(command) with Popen(list_of_args) and this
> > > > > > > > > (according to some) should fix the escaping problem. Needs
> > > > > > > > > testing.
>
> > > > > > > > > Massimo
>
> > > > > > > > > On Jan 30, 4:50 pm, Jonathan Lundell <[email protected]>
> > > > > > > > > wrote:
>
> > > > > > > > > > On Jan 30, 2010, at 1:40 PM, mdipierro wrote:
>
> > > > > > > > > > > The problem is when paths contain spaces.
>
> > > > > > > > > > > I thought even in windows in this case one should esacpe
> > > > > > > > > > > spaces with
> > > > > > > > > > > '\ ' and use either \\ ('\\\\' in python) or / ('/') to
> > > > > > > > > > > separate
> > > > > > > > > > > folders. For example:
>
> > > > > > > > > > > 'C:/windows/Documents\ and\ Settings/'
>
> > > > > > > > > > > or
>
> > > > > > > > > > > 'C:\\windows\\Documents\ and\ Settings\\'
>
> > > > > > > > > > > Am I wrong?
>
> > > > > > > > > > I think so, but I'm no expert on the subject.
>
> > > > > > > > > > Consider that if 'c:\\abc' makes Windows see 'c:\abc', then
> > > > > > > > > > escaping the space isn't going to have any effect.
>
> > > > > > > > > > You can quote a command on the command line, so possibly
> > > > > > > > > > something like:
>
> > > > > > > > > > '"C:\\windows\\Documents and Settings\\"'
>
> > > > > > > > > > might work. Forward slashes are permitted in system calls,
> > > > > > > > > > but IIRC not on the command line, where (at least back in
> > > > > > > > > > the DOS days) they denoted command options (equivalent to -
> > > > > > > > > > in Unix). I'd expect cron entries to be more like
> > > > > > > > > > command-line or batch-file content.
>
> > > > > > > > > > But as I say, I'm no expert.
--
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en.