On Jul 1, 2011, at 8:46 AM, Ross Peoples wrote:
> I'm calling from external cron, which is why this option is not getting set.
> So all I have to do is add --cronjob to my cron line and it's all set.
> Alternatively, while trying to figure this problem out, I noticed that
> global_settings.cmd_options.shell will return a string if run from the shell,
> or None if run as a web request, so if I didn't want to (or couldn't) add
> --cronjob to my script, then I could replace what I used earlier with this:
>
> ############ FORCED SSL #############
> from gluon.settings import global_settings
> if global_settings.cmd_options.shell:
> print 'Running as shell script.'
> elif not request.is_https:
> session.secure()
> redirect('https://%s/%s' % (request.env.http_host, request.application))
> #####################################
>
> So I guess it's personal preference as to whether you would want to add
> --cronjob or check global_settings.cmd_options.shell. Thanks for the help!
For that particular purpose, it might be, but there are other reasons to want
to add --cronjob to cron jobs. I don't recall them all, but there were some
corner cases, such as just after a web2py upgrade, in which the widget.py logic
was getting confused by cron jobs. The --cronjob flag unambiguously tells it to
treat it as a cron job, and -S isn't enough to do that.
So: mark cron invocations with --cronjob (or -J); this happens for you when
web2py is doing it (soft & hard cron), so it's only relevant for external cron.
This should be in the docs, I suppose, if someone would be so kind as to stick
it in.