[IMP] cron: re-use the rlimits (used with Gunicorn) with the cron processes.
bzr revid: vmt@openerp.com-20120330103459-mj7it2zucpiwlc8d
This commit is contained in:
+21
-1
@@ -6,7 +6,26 @@ OpenERP cron jobs worker
|
||||
|
||||
This script executes OpenERP cron jobs. Normally, cron jobs are handled by the
|
||||
OpenERP server but depending on deployment needs, independent worker processes
|
||||
can be used.
|
||||
can be used. This is especially the case when the server is run via Gunicorn.
|
||||
|
||||
OpenERP cron jobs worker re-uses openerp-server command-line options but does
|
||||
not honor all of them.
|
||||
|
||||
Meaningful options include:
|
||||
|
||||
-d, --database comma-separated list of databases to monitor for cron jobs
|
||||
processing. If left empty, the worker monitors all databases
|
||||
(given by `psql -ls`).
|
||||
|
||||
--addons-path as ususal.
|
||||
|
||||
--cpu-time-limte
|
||||
--virtual-memory-limit
|
||||
--virtual-memory-reset Those three options have the same meaning the for
|
||||
the server with Gunicorn. The only catch is: To
|
||||
not enable rlimits by default, those options are
|
||||
honored only when --cpu-time-limte is different than
|
||||
60 (its default value).
|
||||
"""
|
||||
|
||||
import logging
|
||||
@@ -79,6 +98,7 @@ if __name__ == '__main__':
|
||||
openerp.cron.enable_schedule_wakeup = False
|
||||
import openerp.addons.base
|
||||
print "OpenERP cron jobs worker. Hit Ctrl-C to exit."
|
||||
print "Documentation is available at the top of the `opener-cron-worker` file."
|
||||
if config['db_name']:
|
||||
db_names = config['db_name'].split(',')
|
||||
print "Monitoring %s databases." % len(db_names)
|
||||
|
||||
@@ -391,7 +391,22 @@ class ir_cron(osv.osv):
|
||||
return
|
||||
t1 = time.time()
|
||||
for db_name in names:
|
||||
while(cls._acquire_job(db_name)):
|
||||
while True:
|
||||
# Small hack to re-use the openerp-server config:
|
||||
# If the cpu_time_limit has not its default value, we
|
||||
# truly want to establish limits.
|
||||
if openerp.tools.config['cpu_time_limit'] != 60:
|
||||
openerp.wsgi.core.pre_request('dummy', 'dummy')
|
||||
acquired = cls._acquire_job(db_name)
|
||||
if openerp.tools.config['cpu_time_limit'] != 60:
|
||||
class W(object):
|
||||
alive = True
|
||||
worker = W()
|
||||
openerp.wsgi.core.post_request(worker, 'dummy', 'dummy')
|
||||
if not worker.alive:
|
||||
return
|
||||
if not acquired:
|
||||
break
|
||||
if quit_signal_received:
|
||||
return
|
||||
t2 = time.time()
|
||||
|
||||
@@ -506,7 +506,7 @@ def post_request(worker, req, environ):
|
||||
rss, vms = psutil.Process(os.getpid()).get_memory_info()
|
||||
if vms > config['virtual_memory_reset']:
|
||||
_logger.info('Virtual memory consumption '
|
||||
'too high, rebooting the worker.')
|
||||
'too high, killing the worker.')
|
||||
worker.alive = False # Commit suicide after the request.
|
||||
|
||||
# SIGXCPU (exceeded CPU time) signal handler will raise an exception.
|
||||
|
||||
Reference in New Issue
Block a user