diff options
| author | Antony Lesuisse <al@openerp.com> | 2013-04-05 04:42:13 +0200 |
|---|---|---|
| committer | Antony Lesuisse <al@openerp.com> | 2013-04-05 04:42:13 +0200 |
| commit | aa753772ab0be59682fa478dbefb359caf2fabae (patch) | |
| tree | 2956f64c91a7dca650288291f169decd08d76275 | |
| parent | c532e3da9e181c6454d8650428651cccf9e4e6a5 (diff) | |
[IMP] fetchmail, on demand cron
enable a 3 micro hz cron only if needed as we want to lower the maximum
cron frequency in default addons to 1 micro hz
bzr revid: al@openerp.com-20130405024213-ll6t26j685rati5a
| -rw-r--r-- | addons/fetchmail/fetchmail.py | 23 | ||||
| -rw-r--r-- | addons/fetchmail/fetchmail_data.xml | 2 |
2 files changed, 23 insertions, 2 deletions
diff --git a/addons/fetchmail/fetchmail.py b/addons/fetchmail/fetchmail.py index 4edba8cbe3c..230d3e52f5f 100644 --- a/addons/fetchmail/fetchmail.py +++ b/addons/fetchmail/fetchmail.py @@ -90,7 +90,6 @@ class fetchmail_server(osv.osv): 'script': '/mail/static/scripts/openerp_mailgate.py', } - def onchange_server_type(self, cr, uid, ids, server_type=False, ssl=False, object_id=False): port = 0 values = {} @@ -176,7 +175,7 @@ openerp_mailgate: "|/path/to/openerp-mailgate.py --host=localhost -u %(uid)d -p def _fetch_mails(self, cr, uid, ids=False, context=None): if not ids: - ids = self.search(cr, uid, [('state','=','done')]) + ids = self.search(cr, uid, [('state','=','done'),('type','in',['pop','imap'])]) return self.fetch_mail(cr, uid, ids, context=context) def fetch_mail(self, cr, uid, ids, context=None): @@ -241,6 +240,26 @@ 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): + # 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 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) + 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) + return res + class mail_mail(osv.osv): _inherit = "mail.mail" _columns = { diff --git a/addons/fetchmail/fetchmail_data.xml b/addons/fetchmail/fetchmail_data.xml index d77aadc12de..3f6592b340f 100644 --- a/addons/fetchmail/fetchmail_data.xml +++ b/addons/fetchmail/fetchmail_data.xml @@ -10,6 +10,8 @@ <field name="model">fetchmail.server</field> <field name="function">_fetch_mails</field> <field name="args">()</field> + <!-- Active flag is set on fetchmail_server.create/write --> + <field name="active" eval="False"/> </record> </data> </openerp> |
