[IMP] cron: the db_names to monitor can be a callable.
[odoo/odoo.git] / openerp / cron.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 ##############################################################################
4 #
5 #    OpenERP, Open Source Management Solution
6 #    Copyright (C) 2004-2011 OpenERP SA (<http://www.openerp.com>)
7 #
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.
12 #
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.
17 #
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/>.
20 #
21 ##############################################################################
22
23 """ Cron jobs scheduling
24
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.
27
28 It defines a single master thread that will spawn (a bounded number of)
29 threads to process individual cron jobs.
30
31 The thread runs forever, checking every 60 seconds for new
32 'database wake-ups'. It maintains a heapq of database wake-ups. At each
33 wake-up, it will call ir_cron._run_jobs_multithread() for the given database. _run_jobs_multithread
34 will check the jobs defined in the ir_cron table and spawn accordingly threads
35 to process them.
36
37 This module's behavior depends on the following configuration variable:
38 openerp.conf.max_cron_threads.
39
40 """
41
42 import heapq
43 import logging
44 import threading
45 import time
46
47 import openerp
48 import tools
49
50 _logger = logging.getLogger(__name__)
51
52 # TODO: perhaps in the future we could consider a flag on ir.cron jobs
53 # that would cause database wake-up even if the database has not been
54 # loaded yet or was already unloaded (e.g. 'force_db_wakeup' or something)
55
56
57 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: