Does CRON work on GAE?

59 views
Skip to first unread message

Vidul Petrov

unread,
Jul 21, 2009, 1:03:20 AM7/21/09
to web2py-users
Probably this topic has been discussed in the past, but I wasn't able
to find anything.
The cron script works fine (it's implemented as a controller method)
unless running in the GAE testing environment.
The username in app.yml is web2py, the same goes for the username in
"crontab" file.

Thank you for the help.

AchipA

unread,
Jul 21, 2009, 5:39:30 AM7/21/09
to web2py-users
GAE is not supported at the moment, but only because I don't use it
and there was no particular interest in it so far. If GAE has no means
of starting cron-style or long running processes, soft cron should
stil work, provided someone implements a locking mechanism that works
with GAE. The current implementation uses file operations as they are
universal on all platforms (i.e. move file is atomic - that's what the
infamous cron.master is for). Now, AFAIK this would not work on GAE,
but if you give/write an example that would replace that conditional
in a GAE-friendly way it should be no fus to gain cron on GAE out of
the box.

Hans Donner

unread,
Jul 21, 2009, 5:58:50 AM7/21/09
to web...@googlegroups.com

AchipA

unread,
Jul 21, 2009, 6:16:37 AM7/21/09
to web2py-users
Hm, if I understand correctly, we just need a smart crontab ->
cron.yaml converter then, right ? I can imagine other people needing
that too, so there might alredy be such things in the open, could
someone verify that ?
> -http://code.google.com/appengine/docs/python/taskqueue/
>
> perhaps some kind of remapping (like cache) can do the trick
>

Vidul Petrov

unread,
Jul 22, 2009, 9:02:45 PM7/22/09
to web2py-users
It turnes out that the GAE cron daemon does the same work if it comes
to a method invocation (should be a valid URL).
I.e. there is no need for conversion. The problem, as I see it, is the
method protection, what I did is something like:

# the GAE cron file:
# /cron.yaml
cron:
- description: daily note addition
url: /test/default/insert_a_note
schedule: every 1 days

# the default.py controller in init app
# for some reasons Google uses this ip:
valid_inner_ip = "0.1.0.1"

def insert_a_note():
if request.env.remote_addr != valid_inner_ip:
redirect(URL(r=request,f="index"))
...
db.note.insert(name=some_new_name)
...

That's all.

On Jul 21, 1:16 pm, AchipA <attila.cs...@gmail.com> wrote:
> Hm, if I understand correctly, we just need a smart crontab ->cron.yaml converter then, right ? I can imagine other people needing
> that too, so there might alredy be such things in the open, could
> someone verify that ?
>
> On Jul 21, 11:58 am, Hans Donner <hans.don...@pobox.com> wrote:
>
>
>
> >gaehas its own implemementation
>
> > -http://code.google.com/appengine/docs/python/config/cron.html
> > -http://code.google.com/appengine/docs/python/config/queue.html
> > -http://code.google.com/appengine/docs/python/taskqueue/
>
> > perhaps some kind of remapping (like cache) can do the trick
>
> > On Tue, Jul 21, 2009 at 11:39, AchipA<attila.cs...@gmail.com> wrote:
>
> > >GAEis not supported at the moment, but only because I don't use it
> > > and there was no particular interest in it so far. IfGAEhas no means
> > > of startingcron-style or long running processes, softcronshould
> > > stil work, provided someone implements a locking mechanism that works
> > > withGAE. The current implementation uses file operations as they are
> > > universal on all platforms (i.e. move file is atomic - that's what the
> > > infamouscron.master is for). Now, AFAIK this would not work onGAE,
> > > but if you give/write an example that would replace that conditional
> > > in aGAE-friendly way it should be no fus to gaincrononGAEout of
> > > the box.
>
> > > On Jul 21, 7:03 am, Vidul Petrov <vidul.r...@gmail.com> wrote:
> > >> Probably this topic has been discussed in the past, but I wasn't able
> > >> to find anything.
> > >> Thecronscript works fine (it's implemented as a controller method)
> > >> unless running in theGAEtesting environment.

AchipA

unread,
Jul 23, 2009, 5:36:17 AM7/23/09
to web2py-users
Yes, but the advantage of an automatic conversion on deploment would
still be transparent compatibility across all platforms, which is not
a bad thing to have :)

Also, I wished we had a sort of standardized way of having a
@local_only or @auth.ip_in(...) decorator of sorts (maybe we already
do?).

Fran

unread,
Jul 23, 2009, 6:36:49 AM7/23/09
to web2py-users
On Jul 23, 10:36 am, AchipA <attila.cs...@gmail.com> wrote:
> I wished we had a sort of standardized way of having a
> @local_only or @auth.ip_in(...) decorator of sorts

I like it :)
- perhaps reusing the IS_IPV4 validator code

Not sure it would work through proxies though...

> (maybe we already do?).

No - just the template at the top of appadmin.py...

F

mdipierro

unread,
Jul 23, 2009, 7:56:57 AM7/23/09
to web2py-users
you can do:

@auth.requires(lambda: IS_IPV4()(request.client)[1])

works behind a proxy if the proxy uses HTTP_X_FORWARDED_FOR but it can
be spoofed

@auth.requires(lambda: IS_IPV4()(request.addr)[1])

does not work behind a proxy and cannot be spoofed.

Massimo

mdipierro

unread,
Jul 23, 2009, 7:59:06 AM7/23/09
to web2py-users
ERRATA

On Jul 23, 6:56 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> you can do:

@auth.requires(lambda: not IS_IPV4()(request.client)[1])

> works behind a proxy if the proxy uses HTTP_X_FORWARDED_FOR but it can
> be spoofed

@auth.requires(lambda: not IS_IPV4()(request.addr)[1])

Fran

unread,
Jul 23, 2009, 8:01:30 AM7/23/09
to web2py-users
On Jul 23, 12:59 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
> > you can do:
> @auth.requires(lambda: not IS_IPV4()(request.client)[1])
> > works behind a proxy if the proxy uses HTTP_X_FORWARDED_FOR but it can
> > be spoofed
> @auth.requires(lambda: not IS_IPV4()(request.addr)[1])
> > does not work behind a proxy and cannot be spoofed.

A great example for the new book then :)

F
Reply all
Reply to author
Forward
0 new messages