From 430afc1d93d40435598b399156bb5354b5957ed6 Mon Sep 17 00:00:00 2001 From: Sebastien Maillard Date: Thu, 10 Dec 2015 17:12:47 +0800 Subject: [PATCH] Add timeout to urlopen in order to avoid "freeze" of the cron job --- .../models/dead_mans_switch_client.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dead_mans_switch_client/models/dead_mans_switch_client.py b/dead_mans_switch_client/models/dead_mans_switch_client.py index 43c9422df..fa23c1da3 100644 --- a/dead_mans_switch_client/models/dead_mans_switch_client.py +++ b/dead_mans_switch_client/models/dead_mans_switch_client.py @@ -12,6 +12,8 @@ except ImportError: import urllib2 from openerp import api, models +SEND_TIMEOUT = 60 + class DeadMansSwitchClient(models.AbstractModel): _name = 'dead.mans.switch.client' @@ -54,6 +56,10 @@ class DeadMansSwitchClient(models.AbstractModel): if not url: logger.error('No server configured!') return + timeout = self.env['ir.config_parameter'].get_param( + 'dead_mans_switch_client.send_timeout') + if not timeout: + timeout = SEND_TIMEOUT data = self._get_data() logger.debug('sending %s', data) urllib2.urlopen( @@ -66,7 +72,8 @@ class DeadMansSwitchClient(models.AbstractModel): }), { 'Content-Type': 'application/json', - })) + }), + timeout) @api.model def _install_default_url(self):