From ea6184d3d57631df61d52f3ccbe01f62b01fa40f Mon Sep 17 00:00:00 2001 From: Vo Minh Thu Date: Fri, 30 Mar 2012 12:34:59 +0200 Subject: [PATCH] [IMP] cron: re-use the rlimits (used with Gunicorn) with the cron processes. bzr revid: vmt@openerp.com-20120330103459-mj7it2zucpiwlc8d --- openerp-cron-worker | 22 +++++++++++++++++++++- openerp/addons/base/ir/ir_cron.py | 17 ++++++++++++++++- openerp/wsgi/core.py | 2 +- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/openerp-cron-worker b/openerp-cron-worker index a3b2ab0ac55..dd80870dba0 100755 --- a/openerp-cron-worker +++ b/openerp-cron-worker @@ -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) diff --git a/openerp/addons/base/ir/ir_cron.py b/openerp/addons/base/ir/ir_cron.py index cf54a904844..54a2ceab65b 100644 --- a/openerp/addons/base/ir/ir_cron.py +++ b/openerp/addons/base/ir/ir_cron.py @@ -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() diff --git a/openerp/wsgi/core.py b/openerp/wsgi/core.py index 028bb47b349..4fd108ca9ec 100644 --- a/openerp/wsgi/core.py +++ b/openerp/wsgi/core.py @@ -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.