Skip to content

Commit a11dba4

Browse files
committed
[IMP] runbot: allow to link non done batch
To make the propagation faster, mostly for the freeze and to test forwardport chains, allowing to link non done batch (preparing, ready) would allow to start two batch in two version at the same time and cross link them. It is only problematic for upgrades where the template build will be used for upgrade and needs to be finished. The latest changes allows to link a pending template build to an upgrade one and the upgrade waits for the template to finish before starting. The leader also waits for the template in the current batch to be created before starting the configure upgrade. The next part to do is to wait for the template to be created in other batches before starting the configure.
1 parent f033057 commit a11dba4

3 files changed

Lines changed: 43 additions & 11 deletions

File tree

runbot/models/batch.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,20 @@ def _create_build(self, params, slot):
180180
slot.build_id = build
181181
build._prepare_github_status()
182182

183-
def _get_latest_batch_per_version(self, skip_versions):
183+
def _get_latest_batch_per_version(self, skip_versions, done=True):
184+
domain = [
185+
('bundle_id.project_id', '=', self.bundle_id.project_id.id),
186+
('bundle_id.is_base', '=', True),
187+
('bundle_id.sticky', '=', True),
188+
('category_id', '=', self.category_id.id),
189+
('bundle_id.version_id', 'not in', skip_versions.ids),
190+
]
191+
192+
if done:
193+
domain += [('state', '=', 'done')]
194+
184195
return self.env['runbot.batch'].browse(result[1] for result in self.env['runbot.batch']._read_group(
185-
domain=[
186-
('state', '=', 'done'),
187-
('bundle_id.project_id', '=', self.bundle_id.project_id.id),
188-
('bundle_id.is_base', '=', True),
189-
('bundle_id.sticky', '=', True),
190-
('category_id', '=', self.category_id.id),
191-
('bundle_id.version_id', 'not in', skip_versions.ids),
192-
],
196+
domain=domain,
193197
groupby=['bundle_id'],
194198
aggregates=['id:max'],
195199
))
@@ -294,7 +298,7 @@ def _fill_missing(branch_commits, match_type):
294298
if bundle.is_base or auto_rebase:
295299
existing = self.reference_batch_ids
296300
existing_versions = existing.mapped('bundle_id.version_id')
297-
self.reference_batch_ids = self.reference_batch_ids | self._get_latest_batch_per_version(skip_versions=existing_versions)
301+
self.reference_batch_ids = self.reference_batch_ids | self._get_latest_batch_per_version(skip_versions=existing_versions, done=False)
298302
if not bundle.is_base:
299303
merge_base_commits = self.commit_link_ids.mapped('merge_base_commit_id')
300304
if self.base_reference_batch_id:
@@ -483,6 +487,7 @@ def _start_builds(self):
483487
continue
484488
trigger = slot.trigger_id
485489
trigger_custom = trigger_customs.get(trigger, self.env['runbot.bundle.trigger.custom'])
490+
486491
if trigger.starts_after_pending:
487492
missing_triggers = trigger.starts_after_ids - started_trigger
488493
elif trigger.starts_after_failure:
@@ -492,6 +497,21 @@ def _start_builds(self):
492497
if missing_triggers:
493498
if not trigger_custom or (missing_triggers - disabled_triggers):
494499
continue
500+
501+
if trigger.upgrade_dumps_trigger_id and trigger.config_id.uses_referenced_batches:
502+
missing_template = False
503+
for ref_batch in self.reference_batch_ids | self:
504+
if ref_batch.state in ('done', 'skipped'):
505+
continue
506+
if ref_batch.state == 'preparing':
507+
missing_template = True
508+
break
509+
needed_slot = ref_batch.slot_ids.filtered(lambda s: s.trigger_id in trigger.upgrade_dumps_trigger_id)
510+
if not needed_slot or not needed_slot.build_id:
511+
missing_template = True
512+
break
513+
if missing_template:
514+
continue
495515
force_trigger = trigger_custom and trigger_custom.start_mode == 'force'
496516
skip_trigger = (trigger_custom and trigger_custom.start_mode == 'disabled') or trigger.manual
497517
should_start = slot.trigger_id.id in should_start_triggers_ids

runbot/models/build_config.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ class Config(models.Model):
144144
dynamic_config_extension = fields.Text('Dynamic Config Extend File', tracking=True)
145145

146146
use_extra_slot = fields.Boolean('Use extra slot', default=False, tracking=True, help="Allow to use an extra slot for this config, if available")
147+
uses_referenced_batches = fields.Boolean('Uses references builds', compute='_compute_uses_referenced_batches', store=True)
148+
149+
@api.depends('step_order_ids.step_id.uses_referenced_batches')
150+
def _compute_uses_referenced_batches(self):
151+
for record in self:
152+
record.uses_referenced_batches = any(step.uses_referenced_batches for step in record.step_order_ids.step_id)
147153

148154
@api.constrains('default_dynamic_config', 'dynamic_config_extension')
149155
def _check_dynamic_config(self):
@@ -508,7 +514,7 @@ class ConfigStep(models.Model):
508514
file_limit = fields.Integer('File limit', default=450)
509515
break_before_if_ko = fields.Boolean('Break before this step if build is ko')
510516
break_after_if_ko = fields.Boolean('Break after this step if build is ko')
511-
517+
uses_referenced_batches = fields.Boolean('Uses references builds', compute='_compute_uses_referenced_batches', store=True, readonly=False)
512518

513519
@api.constrains('python_code')
514520
def _check_python_code(self):
@@ -536,6 +542,11 @@ def _compute_db_name(self):
536542
for step in self:
537543
step.db_name = step.custom_db_name or step.name
538544

545+
@api.depends('job_type')
546+
def _compute_uses_referenced_batches(self):
547+
for record in self:
548+
record.uses_referenced_batches = record.job_type == 'configure_upgrade'
549+
539550
def _get_db_name(self, build):
540551
db_name = self.custom_db_name or self.name
541552
return re.sub(r'[^a-z0-9\-_]', '_', db_name.lower())

runbot/views/config_views.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
<field name="allow_similar_build_quick_result"/>
111111
<field name="allow_build_link"/>
112112
<field name="upgrade_matrix_id"/>
113+
<field name="uses_referenced_batches"/>
113114
</group>
114115
<group invisible="job_type not in ('python', 'configure_upgrade', 'dynamic')">
115116
<group class="col" string="Upgrade matrix settings" invisible="not upgrade_matrix_id">

0 commit comments

Comments
 (0)