This commit is contained in:
Xavier-Do 2024-12-17 14:06:20 +01:00
parent 09b14e1702
commit be4d67bfc1
2 changed files with 20 additions and 3 deletions

View File

@ -238,6 +238,7 @@ class BuildResult(models.Model):
commit_export_ids = fields.One2many('runbot.commit.export', 'build_id')
static_run = fields.Char('Static run URL')
db_garbage_collected = fields.Boolean()
access_token = fields.Char('Token', default=lambda self: uuid.uuid4().hex)
@ -962,6 +963,7 @@ class BuildResult(models.Model):
def _local_pg_dropdb(self, dbname):
msg = ''
self._build_from_dest(dbname).db_garbage_collected = True
try:
with local_pgadmin_cursor() as local_cr:
query = 'SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname=%s'
@ -1046,6 +1048,15 @@ class BuildResult(models.Model):
for child in build.children_ids:
child._ask_kill(lock=False)
def _can_wake_up(self):
return (
self.local_state == "done" and
self.requested_action != 'wake_up' and
self.host_id.active and
self.database_ids and
(not self.parent_id.database_ids or self.env.user.has_group('runbot.group_runbot_advanced_user'))
)
def _wake_up(self):
user = self.env.user
self._log('wake_up', f'Wake up initiated by {user.name}')
@ -1269,3 +1280,4 @@ class BuildResult(models.Model):
def _parse_config(self):
return set(findall(self._server("tools/config.py"), r'--[\w-]+', ))

View File

@ -259,7 +259,12 @@
<a t-if="bu.static_run" t-att-href="bu.static_run" class="btn btn-info" title="View result" aria-label="View result">
<i class="fa fa-sign-in"/>
</a>
<a groups="base.group_user" t-if="bu.local_state=='done' and (not bu.parent_id.database_ids or user_id.has_group('runbot.group_runbot_advanced_user')) and bu.requested_action != 'wake_up' and bu.database_ids" href="#" data-runbot="wakeup" t-att-data-runbot-build="bu.id" class="btn btn-default" title="Wake up this build" aria-label="Wake up this build">
<a groups="base.group_user"
t-if="bu._can_wake_up()"
href="#" data-runbot="wakeup" t-att-data-runbot-build="bu.id"
t-attf-class="btn btn-{{'default' if not bu.db_garbage_collected else 'danger'}}"
t-attf-title="Wake up this build {{'' if not bu.db_garbage_collected else '(No database found, may create an empty one)'}}"
aria-label="Wake up this build">
<i class="fa fa-coffee"/>
</a>
<a t-attf-href="/runbot/build/{{bu['id']}}" class="btn btn-default" title="Build details" aria-label="Build details">
@ -334,8 +339,8 @@
</a>
</t>
</t>
<t t-if="bu.global_state == 'done'">
<t t-if="bu.requested_action != 'wake_up' and bu.database_ids">
<t t-if="bu.local_state == 'done'">
<t t-if="bu._can_wake_up() and not bu.db_garbage_collected">
<a groups="base.group_user" class="dropdown-item" href="#" data-runbot="wakeup" t-att-data-runbot-build="bu['id']">
<i class="fa fa-coffee"/>
Wake up