From 6bc666b5c3ee53642e77d95cb33fdc4e2a00d379 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Wed, 3 Jul 2019 16:02:15 +0200 Subject: [PATCH] [IMP] runbot: avoid loosing hooks In the same spirit of getting garanties that community is updated when enterprise is, force the hook time of dependencies in case it was lost. --- runbot/__manifest__.py | 2 +- runbot/controllers/hook.py | 6 ++++-- runbot/models/repo.py | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/runbot/__manifest__.py b/runbot/__manifest__.py index 842e9435..790ac6f6 100644 --- a/runbot/__manifest__.py +++ b/runbot/__manifest__.py @@ -6,7 +6,7 @@ 'author': "Odoo SA", 'website': "http://runbot.odoo.com", 'category': 'Website', - 'version': '4.1', + 'version': '4.2', 'depends': ['website', 'base'], 'data': [ 'security/runbot_security.xml', diff --git a/runbot/controllers/hook.py b/runbot/controllers/hook.py index f944fff6..dec17da9 100644 --- a/runbot/controllers/hook.py +++ b/runbot/controllers/hook.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -import datetime +import time import json from odoo import http, tools @@ -25,5 +25,7 @@ class RunbotHook(http.Controller): repo_id = repo.id repo = request.env['runbot.repo'].sudo().browse([repo_id]) - repo.hook_time = datetime.datetime.now().strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT) + + # force update of dependencies to in case a hook is lost + (repo | repo.dependency_ids).write({'hook_time': time.time()}) return "" diff --git a/runbot/models/repo.py b/runbot/models/repo.py index cb1e7544..8d5a2e74 100644 --- a/runbot/models/repo.py +++ b/runbot/models/repo.py @@ -35,7 +35,7 @@ class runbot_repo(models.Model): ('hook', 'Hook')], default='poll', string="Mode", required=True, help="hook: Wait for webhook on /runbot/hook/ i.e. github push event") - hook_time = fields.Datetime('Last hook time') + hook_time = fields.Float('Last hook time') get_ref_time = fields.Float('Last refs db update') duplicate_id = fields.Many2one('runbot.repo', 'Duplicate repo', help='Repository for finding duplicate builds') modules = fields.Char("Modules to install", help="Comma-separated list of modules to install and test.") @@ -327,10 +327,10 @@ class runbot_repo(models.Model): fname_fetch_head = os.path.join(repo.path, 'FETCH_HEAD') if not force and os.path.isfile(fname_fetch_head): fetch_time = os.path.getmtime(fname_fetch_head) - if repo.mode == 'hook' and (not repo.hook_time or dt2time(repo.hook_time) < fetch_time): + if repo.mode == 'hook' and (not repo.hook_time or repo.hook_time < fetch_time): t0 = time.time() _logger.debug('repo %s skip hook fetch fetch_time: %ss ago hook_time: %ss ago', - repo.name, int(t0 - fetch_time), int(t0 - dt2time(repo.hook_time)) if repo.hook_time else 'never') + repo.name, int(t0 - fetch_time), int(t0 - repo.hook_time) if repo.hook_time else 'never') return self._update_fetch_cmd()