From 430afc1d93d40435598b399156bb5354b5957ed6 Mon Sep 17 00:00:00 2001 From: Sebastien Maillard Date: Thu, 10 Dec 2015 17:12:47 +0800 Subject: [PATCH 1/2] 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): From 1a1e6c08211655f49a786b987d18992441d9e887 Mon Sep 17 00:00:00 2001 From: Sebastien Maillard Date: Thu, 10 Dec 2015 19:27:12 +0800 Subject: [PATCH 2/2] Use default timeout in get_param directly --- dead_mans_switch_client/models/dead_mans_switch_client.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) 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 fa23c1da3..2d23ef05e 100644 --- a/dead_mans_switch_client/models/dead_mans_switch_client.py +++ b/dead_mans_switch_client/models/dead_mans_switch_client.py @@ -57,9 +57,7 @@ class DeadMansSwitchClient(models.AbstractModel): 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 + 'dead_mans_switch_client.send_timeout', SEND_TIMEOUT) data = self._get_data() logger.debug('sending %s', data) urllib2.urlopen(