Skip to content

Commit 1a8f82c

Browse files
committed
wip
1 parent ae7b633 commit 1a8f82c

3 files changed

Lines changed: 57 additions & 15 deletions

File tree

runbot/models/build.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,12 @@ class BuildResult(models.Model):
345345
string='Build type')
346346

347347
parent_id = fields.Many2one('runbot.build', 'Parent Build', index=True)
348+
parent_link_ids = fields.One2many('runbot.build.link', 'child_id', string='Used in links')
349+
parent_ids = fields.Many2many('runbot.build', related='parent_link_ids.parent_id')
350+
351+
child_link_ids = fields.One2many('runbot.build.link', 'parent_id', string='Child links')
352+
353+
348354
parent_path = fields.Char('Parent path', index=True)
349355
top_parent = fields.Many2one('runbot.build', compute='_compute_top_parent')
350356
ancestors = fields.Many2many('runbot.build', compute='_compute_ancestors')
@@ -525,7 +531,7 @@ def write(self, values):
525531

526532
return res
527533

528-
def _add_child(self, param_values, orphan=False, description=False, additionnal_commit_links=False):
534+
def _add_child(self, param_values, orphan=False, description=False, additionnal_commit_links=False, link=False):
529535
build_values = {key: value for key, value in param_values.items() if key not in self.params_id._fields}
530536
param_values = {key: value for key, value in param_values.items() if key in self.params_id._fields}
531537

@@ -538,17 +544,40 @@ def _add_child(self, param_values, orphan=False, description=False, additionnal_
538544
commit_link_ids |= additionnal_commit_links
539545
param_values['commit_link_ids'] = commit_link_ids
540546

541-
return self.create({
542-
'params_id': self.params_id.copy(param_values).id,
543-
'parent_id': self.id,
547+
params = self.params_id.copy(param_values)
548+
549+
build_values = {
550+
'params_id': params.id,
544551
'build_type': self.build_type,
545552
'priority_level': self.priority_level,
546553
'description': description,
547554
'orphan_result': orphan,
548555
'keep_host': self.keep_host,
549556
'host': self.host if self.keep_host else False,
550557
**build_values,
551-
})
558+
}
559+
560+
if link:
561+
existing_builds = params.build_ids
562+
if self.keep_host:
563+
existing_builds = existing_builds.filtered(lambda b: b.host == self.host)
564+
if existing_builds:
565+
build = existing_builds.sorted('id')[-1]
566+
build.killable = False
567+
568+
if build:
569+
build = self.create(build_values)
570+
571+
self.env['runbot.build.link'].create({
572+
'parent_id': self.id,
573+
'child_id': link,
574+
})
575+
return build
576+
else:
577+
return self.create({
578+
'parent_id': self.id,
579+
**build_values,
580+
})
552581

553582
@api.depends('params_id.version_id.name')
554583
def _compute_dest(self):
@@ -1627,5 +1656,5 @@ class BuildLink(models.Model):
16271656

16281657
parent_id = fields.Many2one('runbot.build', string='Parent Build', required=True, ondelete='cascade')
16291658
child_id = fields.Many2one('runbot.build', string='Child Build', required=True, ondelete='cascade')
1630-
params_id = fields.Many2one('runbot.params', string='Params', related='child_id.params_id', store=True)
1631-
1659+
params_id = fields.Many2one('runbot.build.params', string='Params', related='child_id.params_id', store=True)
1660+
orphan_result = fields.Boolean(string='Orphan Result', help='If set, the result of the child build will not be taken into account for the parent build result')

runbot/models/build_config.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ def get_reference_builds_for_versions(versions):
10131013
'version_id': target.params_id.version_id.id,
10141014
'trigger_id': None,
10151015
'dockerfile_id': target.params_id.dockerfile_id.id,
1016-
})
1016+
}, link=True)
10171017
source_description = source.params_id.version_id.name
10181018
target_description = target.params_id.version_id.name
10191019
if source in build.create_batch_id.slot_ids.build_id:
@@ -1026,12 +1026,12 @@ def get_reference_builds_for_versions(versions):
10261026
db.name,
10271027
)
10281028

1029-
if self.allow_similar_build_quick_result:
1030-
existing_done_build = next((build for build in child.params_id.build_ids.sorted('id') if build.global_state == 'done' and build.local_result not in ('skipped', 'killed')), None)
1031-
if existing_done_build:
1032-
child._log('', 'A similar [build](%s) has been found, marking as done directly', existing_done_build.build_url, log_type='markdown')
1033-
child.local_state = 'done'
1034-
child.local_result = existing_done_build.local_result
1029+
#if self.allow_similar_build_quick_result:
1030+
# existing_done_build = next((build for build in child.params_id.build_ids.sorted('id') if build.global_state == 'done' and build.local_result not in ('skipped', 'killed')), None)
1031+
# if existing_done_build:
1032+
# child._log('', 'A similar [build](%s) has been found, marking as done directly', existing_done_build.build_url, log_type='markdown')
1033+
# child.local_state = 'done'
1034+
# child.local_result = existing_done_build.local_result
10351035

10361036
def _filter_upgrade_database(self, dbs, pattern):
10371037
pat_list = pattern.split(',') if pattern else []

runbot/models/runbot.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,22 @@ def _gc_testing(self, host):
127127
if available_slots > 0 or nb_pending == 0:
128128
return
129129

130+
killable_build = []
131+
130132
for build in testing_builds:
131133
if build.top_parent.killable:
132-
build.top_parent._ask_kill(message='Build automatically killed, new build found.')
134+
killable_build.append(build)
135+
continue
136+
if not build.parent_id and build.parent_ids:
137+
killable_build.append(build)
138+
continue
139+
140+
for build in killable_build:
141+
build._log('_ask_kill', "Build automatically killed, new build found.")
142+
if build.local_state == 'pending':
143+
build._skip()
144+
elif build.local_state in ['testing', 'running']:
145+
build.requested_action = 'deathrow'
133146

134147
def _allocate_builds(self, host, nb_slots, domain=None):
135148
if nb_slots <= 0:

0 commit comments

Comments
 (0)