diff --git a/runbot/data/runbot_data.xml b/runbot/data/runbot_data.xml index 7123ca9f..254b2b1d 100644 --- a/runbot/data/runbot_data.xml +++ b/runbot/data/runbot_data.xml @@ -97,14 +97,4 @@ admin_passwd=running_master_password records.write({'no_build': False}) - - - Runbot - - 10 - seconds - - model._cron() - code - diff --git a/runbot/models/runbot.py b/runbot/models/runbot.py index 2e038108..4677c119 100644 --- a/runbot/models/runbot.py +++ b/runbot/models/runbot.py @@ -196,53 +196,6 @@ class Runbot(models.AbstractModel): else: _logger.warning('failed to start nginx - failed to kill orphan worker - oh well') - def _get_cron_period(self): - """ Compute a randomized cron period with a 2 min margin below - real cron timeout from config. - """ - cron_limit = config.get('limit_time_real_cron') - req_limit = config.get('limit_time_real') - cron_timeout = cron_limit if cron_limit > -1 else req_limit - return cron_timeout / 2 - - def _cron(self): - """ - This method is the default cron for new commit discovery and build sheduling. - The cron runs for a long time to avoid spamming logs - """ - pull_info_failures = {} - start_time = time.time() - timeout = self._get_cron_period() - get_param = self.env['ir.config_parameter'].get_param - update_frequency = int(get_param('runbot.runbot_update_frequency', default=10)) - runbot_do_fetch = get_param('runbot.runbot_do_fetch') - runbot_do_schedule = get_param('runbot.runbot_do_schedule') - host = self.env['runbot.host']._get_current() - host._set_psql_conn_count() - host.last_start_loop = fields.Datetime.now() - self._commit() - # Bootstrap - host._bootstrap() - if runbot_do_schedule: - host._docker_update_images() - self._source_cleanup() - self.env['runbot.build']._local_cleanup() - self._docker_cleanup() - _logger.info('Starting loop') - if runbot_do_schedule or runbot_do_fetch: - while time.time() - start_time < timeout: - if runbot_do_fetch: - self._fetch_loop_turn(host, pull_info_failures) - if runbot_do_schedule: - sleep_time = self._scheduler_loop_turn(host, update_frequency) - time.sleep(sleep_time) - else: - time.sleep(update_frequency) - self._commit() - - host.last_end_loop = fields.Datetime.now() - - def _fetch_loop_turn(self, host, pull_info_failures, default_sleep=1): with self._manage_host_exception(host) as manager: repos = self.env['runbot.repo'].search([('mode', '!=', 'disabled')]) diff --git a/runbot/templates/dashboard.xml b/runbot/templates/dashboard.xml index a5d648c8..e894e157 100644 --- a/runbot/templates/dashboard.xml +++ b/runbot/templates/dashboard.xml @@ -133,16 +133,16 @@ - + success - + info - + danger - + diff --git a/runbot/tests/__init__.py b/runbot/tests/__init__.py index e4410f29..3db76a69 100644 --- a/runbot/tests/__init__.py +++ b/runbot/tests/__init__.py @@ -5,7 +5,6 @@ from . import test_build_error from . import test_branch from . import test_build from . import test_schedule -from . import test_cron from . import test_build_config_step from . import test_event from . import test_command diff --git a/runbot/tests/test_cron.py b/runbot/tests/test_cron.py deleted file mode 100644 index d00d7763..00000000 --- a/runbot/tests/test_cron.py +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -from unittest.mock import patch -from .common import RunbotCase - - -class SleepException(Exception): - ... - - -def sleep(time): - raise SleepException() - - -class TestCron(RunbotCase): - - def setUp(self): - super(TestCron, self).setUp() - self.start_patcher('list_local_dbs_patcher', 'odoo.addons.runbot.models.host.list_local_dbs', ['runbot_logs']) - self.start_patcher('_get_cron_period', 'odoo.addons.runbot.models.runbot.Runbot._get_cron_period', 2) - - @patch('time.sleep', side_effect=sleep) - @patch('odoo.addons.runbot.models.repo.Repo._update_batches') - def test_cron_schedule(self, mock_update_batches, *args): - """ test that cron_fetch_and_schedule do its work """ - self.env['ir.config_parameter'].sudo().set_param('runbot.runbot_update_frequency', 1) - self.env['ir.config_parameter'].sudo().set_param('runbot.runbot_do_fetch', True) - self.env['runbot.repo'].search([('id', '!=', self.repo_server.id)]).write({'mode': 'disabled'}) # disable all other existing repo than repo_server - try: - self.Runbot._cron() - except SleepException: - pass # sleep raises an exception to avoid to stay stuck in loop - mock_update_batches.assert_called() - - @patch('time.sleep', side_effect=sleep) - @patch('odoo.addons.runbot.models.host.Host._docker_update_images') - @patch('odoo.addons.runbot.models.host.Host._bootstrap') - @patch('odoo.addons.runbot.models.runbot.Runbot._scheduler') - def test_cron_build(self, mock_scheduler, mock_host_bootstrap, mock_host_docker_update_images, *args): - """ test that cron_fetch_and_build do its work """ - hostname = 'cronhost.runbot.com' - self.patchers['hostname_patcher'].return_value = hostname - self.env['ir.config_parameter'].sudo().set_param('runbot.runbot_update_frequency', 1) - self.env['ir.config_parameter'].sudo().set_param('runbot.runbot_do_schedule', True) - self.env['runbot.repo'].search([('id', '!=', self.repo_server.id)]).write({'mode': 'disabled'}) # disable all other existing repo than repo_server - - try: - self.Runbot._cron() - except SleepException: - pass # sleep raises an exception to avoid to stay stuck in loop - mock_scheduler.assert_called() - mock_host_bootstrap.assert_called() - mock_host_docker_update_images.assert_called() - host = self.env['runbot.host'].search([('name', '=', hostname)]) - self.assertTrue(host, 'A new host should have been created') - # self.assertGreater(host.psql_conn_count, 0, 'A least one connection should exist on the current psql batch')