summaryrefslogtreecommitdiff
path: root/addons/fetchmail/fetchmail.py
diff options
context:
space:
mode:
authorStéphane Wirtel <stephane@wirtel.be>2014-06-12 15:08:33 +0200
committerJulien Legros <jle@odoo.com>2014-09-02 18:32:27 +0200
commit1ff7ed275845589ea8b8d27c7dbd17e5a282626e (patch)
treea3149610b704f699a1caa6f9b2e88b16064610e5 /addons/fetchmail/fetchmail.py
parentc3f52899dd0ba85615be8cf08a541c8a76ca430e (diff)
[IMP] Optimize the schedulers of the calendar, fetchmail and base_action_rules modules
Disable the the crons when they'd have nothing to do, re-enable them when a task is (probably) introduced
Diffstat (limited to 'addons/fetchmail/fetchmail.py')
-rw-r--r--addons/fetchmail/fetchmail.py34
1 files changed, 20 insertions, 14 deletions
diff --git a/addons/fetchmail/fetchmail.py b/addons/fetchmail/fetchmail.py
index 565996bf961..37a0f165435 100644
--- a/addons/fetchmail/fetchmail.py
+++ b/addons/fetchmail/fetchmail.py
@@ -251,27 +251,33 @@ openerp_mailgate: "|/path/to/openerp-mailgate.py --host=localhost -u %(uid)d -p
server.write({'date': time.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)})
return True
- def cron_update(self, cr, uid, context=None):
- if context is None:
- context = {}
- if not context.get('fetchmail_cron_running'):
- # Enabled/Disable cron based on the number of 'done' server of type pop or imap
- ids = self.search(cr, uid, [('state','=','done'),('type','in',['pop','imap'])])
- try:
- cron_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'fetchmail', 'ir_cron_mail_gateway_action')[1]
- self.pool.get('ir.cron').write(cr, 1, [cron_id], {'active': bool(ids)})
- except ValueError:
- # Nevermind if default cron cannot be found
- pass
+ def _update_cron(self, cr, uid, context=None):
+ if context and context.get('fetchmail_cron_running'):
+ return
+
+ try:
+ cron = self.pool['ir.model.data'].get_object(
+ cr, uid, 'fetchmail', 'ir_cron_mail_gateway_action', context=context)
+ except ValueError:
+ # Nevermind if default cron cannot be found
+ return
+
+ # Enabled/Disable cron based on the number of 'done' server of type pop or imap
+ cron.toggle(model=self._name, domain=[('state','=','done'), ('type','in',['pop','imap'])])
def create(self, cr, uid, values, context=None):
res = super(fetchmail_server, self).create(cr, uid, values, context=context)
- self.cron_update(cr, uid, context=context)
+ self._update_cron(cr, uid, context=context)
return res
def write(self, cr, uid, ids, values, context=None):
res = super(fetchmail_server, self).write(cr, uid, ids, values, context=context)
- self.cron_update(cr, uid, context=context)
+ self._update_cron(cr, uid, context=context)
+ return res
+
+ def unlink(self, cr, uid, ids, context=None):
+ res = super(fetchmail_server, self).unlink(cr, uid, ids, context=context)
+ self._update_cron(cr, uid, context=context)
return res
class mail_mail(osv.osv):