2 # -*- coding: utf-8 -*-
3 ##############################################################################
5 # OpenERP, Open Source Management Solution
6 # Copyright (C) 2004-2011 OpenERP SA (<http://www.openerp.com>)
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as
10 # published by the Free Software Foundation, either version 3 of the
11 # License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
23 """ Cron jobs scheduling
25 Cron jobs are defined in the ir_cron table/model. This module deals with all
26 cron jobs, for all databases of a single OpenERP server instance.
36 _logger = logging.getLogger(__name__)
38 SLEEP_INTERVAL = 60 # 1 min
40 def cron_runner(number):
42 time.sleep(SLEEP_INTERVAL + number) # Steve Reich timing style
43 registries = openerp.modules.registry.RegistryManager.registries
44 _logger.debug('cron%d polling for jobs', number)
45 for db_name, registry in registries.items():
46 while True and registry.cron:
47 # acquired = openerp.addons.base.ir.ir_cron.ir_cron._acquire_job(db_name)
48 # TODO why isnt openerp.addons.base defined ?
50 base = sys.modules['addons.base']
51 acquired = base.ir.ir_cron.ir_cron._acquire_job(db_name)
56 """ Start the above runner function in a daemon thread.
58 The thread is a typical daemon thread: it will never quit and must be
59 terminated when the main process exits - with no consequence (the processing
60 threads it spawns are not marked daemon).
63 for i in range(openerp.tools.config['max_cron_threads']):
66 t = threading.Thread(target=target, name="openerp.service.cron.cron%d" % i)
69 _logger.debug("cron%d started!" % i)
74 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: