Merge lp:~achipa/web2py/cron into lp:~mdipierro/web2py/devel

Proposed by Attila Csipa
Status: Merged
Merge reported by: Attila Csipa
Merged at revision: not available
Proposed branch: lp:~achipa/web2py/cron
Merge into: lp:~mdipierro/web2py/devel
Diff against target: None lines
To merge this branch: bzr merge lp:~achipa/web2py/cron
Reviewer Review Type Date Requested Status
Massimo Approve
Review via email: mp+4011@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Attila Csipa (achipa) wrote :

wsgihooks fix and examples docs

lp:~achipa/web2py/cron updated
559. By Massimo Di Pierro <email address hidden>

modified gaehandler to allow subdirs, thank you Markus

560. By Massimo Di Pierro <email address hidden>

-p and -i no longer ignored by widget

561. By Massimo Di Pierro <email address hidden>

added __init__.py, thank you Markus

562. By Massimo Di Pierro <email address hidden>

pool_size, thanks Markus

563. By Massimo Di Pierro <email address hidden>

Edit keep alive and ajax save with feedback, thanks Boris Manojlovic

564. By Massimo Di Pierro <email address hidden>

Edit keep alive and ajax save with feedback, thanks Boris Manojlovic

565. By Massimo Di Pierro <email address hidden>

force closing connections, thanks Achipa

Revision history for this message
Massimo (mdipierro) wrote :

posted in revision 567

review: Approve
lp:~achipa/web2py/cron updated
566. By Massimo Di Pierro <email address hidden>

achipa cron patch

567. By Massimo Di Pierro <email address hidden>

achipa cron patch

Revision history for this message
Massimo (mdipierro) wrote :

this is in

On Feb 27, 2009, at 6:15 AM, AttilaCsipa wrote:

> AttilaCsipa has proposed merging lp:~achipa/web2py/cron into
> lp:~mdipierro/web2py/devel.
>
> Requested reviews:
> Massimo (mdipierro)
>
> wsgihooks fix and examples docs
> --
> https://code.launchpad.net/~achipa/web2py/cron/+merge/4011
> You are requested to review the proposed merge of lp:~achipa/web2py/
> cron into lp:~mdipierro/web2py/devel.
> <review.diff>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'applications/examples/controllers/default.py'
2--- applications/examples/controllers/default.py 2009-02-20 05:13:24 +0000
3+++ applications/examples/controllers/default.py 2009-02-27 12:05:24 +0000
4@@ -55,3 +55,6 @@
5
6 def security():
7 return response.render(dict())
8+
9+def cron():
10+ return response.render(dict())
11
12=== added file 'applications/examples/views/default/cron.html'
13--- applications/examples/views/default/cron.html 1970-01-01 00:00:00 +0000
14+++ applications/examples/views/default/cron.html 2009-02-27 12:05:24 +0000
15@@ -0,0 +1,87 @@
16+{{extend 'layout.html'}}
17+{{import os}}
18+
19+<h1>web2py<sup style="font-size:0.5em;">TM</sup> cron</h1>
20+
21+The web2py cron provides the ability for applications to execute tasks at preset times, in a platform independent manner (tested on Windows XP, Linux and MacOS X, but should work on any python 2.5 supported platform).
22+
23+Cron functionality is defined by a crontab file (in regular <A href="http://en.wikipedia.org/wiki/Cron#crontab_syntax">crontab syntax</A>) in your application's cron directory. This also means that every application can have a separate cron configuration and that cron config can be changed from within web2py without affecting the host OS itself.
24+<BR>
25+<BR>
26+Example:
27+{{=CODE(""" 0-59/1 * * * * root python /path/to/python/script.py
28+*/30 * * * * root *applications/admin/cron/expire_sessions.py
29+-1 * * * * root *mycontroller/myfunction""")}}
30+
31+As you might have noticed, some of the lines use <A href="#extensions">extensions</A> to regular cron syntax to provide additional web2py functionality.
32+
33+<BR>
34+<h2>Modes of use</h2>
35+
36+Depending on how you are invoking web2py, there are four modes of operation for web2py cron.
37+
38+<UL>
39+<LI><A href="#soft">Soft cron</A>, available under all execution modes</LI>
40+<LI><A href="#hard">Hard cron</A>, available if using the built-in web server (either directly or via Apache mod_proxy)</LI>
41+<LI><A href="#external">External cron</A>, available if you have access to the systems own cron service</LI>
42+<LI><A href="#no">No cron</A></LI>
43+</UL>
44+
45+The default is hard cron if you are using the built-in web server, in all other cases the default is soft-cron.
46+
47+
48+<h3 id="soft">Soft cron</h3>
49+
50+Soft cron is the default if you are using CGI, FASTCGI or WSGI. Your tasks will be executed in the first call (page load) to web2py after the time specified in crontab (but AFTER processing the page, so no delay to the user is visible). Obviously, there is some uncertainty exactly when the task will be executed depending on the traffic the site receives. Also, the cron task may get interrupted if the web server has a page load timeout set. If these limitations are not acceptable, see <A href="#external">external cron</A>. Soft cron is a reasonable last resort, but if your web server allows other cron methods, they should be preferred over soft cron.
51+
52+<h3 id="hard">Hard cron</h3>
53+
54+Hard cron is the default if you are using the built-in web server (either directly or via Apache mod_proxy). Hard cron is executed in a parallel thread, so unlike soft cron there are no limitations with regard to run time or execution time precision.
55+
56+<h3 id="external">External cron</h3>
57+
58+External cron is not default in any scenarios, but requires you to have access to the system cron facilities. It runs in a parallel process, so none of the limitations of soft cron apply. This is the recommended way of using cron under WSGI or FASTCGI.
59+<BR>
60+<BR>
61+
62+Example of line to add to the system crontab, (usually /etc/crontab):
63+{{=CODE("""0-59/1 * * * * web2py cd /var/www/web2py/ && touch applications/admin/cron/cron.master && python web2py.py -C -D 1 >> /tmp/cron.output 2>&1""")}}
64+
65+If you are running external cron, make sure you add the -N command line parameter to your web2py startup script or config so there is no collision of multiple types of cron.
66+
67+<h3 id="no">No cron</h3>
68+
69+In case you do not need any cron functionality, you can use the -N command line parameter to disable it. Note that this will disable some maintenance tasks (like the automatic cleaning of session dirs).
70+
71+<BR>
72+<h2 id="extensions">Cron extensions</h2>
73+
74+Web2py cron has a some extra syntax to support web2py application specifics.
75+
76+<h3>Calling scripts in the web2py environment</h3>
77+
78+If the task/script is prefixed with an asterisk and ends with ".py", it will be executed in the web2py environment. This means you will have all the controllers and models at your disposal. Warning: be careful how you use models. While the execution happens in a separate process, database locks have to be taken into account in order to avoid pages waiting for cron tasks that be blocking the database.
79+
80+<BR>
81+<BR>
82+Example:
83+{{=CODE("""*/30 * * * * root *applications/admin/cron/expire_sessions.py""")}}
84+
85+<h3>Calling controller functions</h3>
86+
87+Same as above, but a function from a controller is executed instead of a separate script file.
88+<BR>
89+<BR>
90+
91+Example:
92+{{=CODE("""*/30 * * * * root *mycontroller/myfunction""")}}
93+
94+<h3>Application initialization</h3>
95+
96+If you specify -1 as minutes in the crontab file, the given task will be executed only ONCE, on web2py startup. You can use this feature if you want to precache, check or initialize data for an application on web2py startup.
97+
98+Example:
99+{{=CODE("""
100+-1 * * * * root *mycontroller/myfunction
101+""")}}
102+
103
104=== modified file 'applications/examples/views/default/index.html'
105--- applications/examples/views/default/index.html 2009-02-20 05:13:24 +0000
106+++ applications/examples/views/default/index.html 2009-02-27 12:05:24 +0000
107@@ -32,7 +32,7 @@
108 <li>Includes <a href="http://www.jquery.com">jQuery</a> for Effects and Ajax</li>
109 <li>Includes a powerful Python-based template language to render objects into HTML or other text-based protocols</li>
110 <li>Handles automatically upload and download <a href="{{=URL(r=request,f='examples#example_stream')}}">streaming</a> for large media files</li>
111-<li>Includes portable cron mechanism for creating and running recurrent tasks in background</li>
112+<li>Includes portable <A href="{{=URL(r=request,f='cron')}}">cron</A> mechanism for creating and running recurrent tasks in background</li>
113 <li><a href="{{=URL(r=request,f='license')}}">Allows</a> to bytecode-compile applications and distribute them in closed source</li>
114 <li>We guarantee backward compatibility of the web2py API since 1.0</li>
115 </ul>
116
117=== modified file 'gluon/contrib/wsgihooks.py'
118--- gluon/contrib/wsgihooks.py 2009-02-03 17:38:58 +0000
119+++ gluon/contrib/wsgihooks.py 2009-02-27 11:18:33 +0000
120@@ -47,7 +47,7 @@
121 try:
122 result = self.__application(environ, start_response)
123 except:
124- self.__callback(self.__environ)
125+ self.__callback(environ)
126 raise
127 return Generator2(result, self.__callback, environ)
128
129@@ -63,17 +63,6 @@
130 threading.Thread.__init__(self)
131 self.env = env
132
133-
134-# def run():
135-# if self.func:
136-# return self.func
137-
138-# class PreConnectionTask(threading.Thread):
139-# def run(self):
140-# import logging
141-# logging.warning("pre")
142-
143-
144 def callback(env):
145 global globalposttasks
146 global localposttasks