[IMP] rubnbot_merge: avoid triggering every cron on every test

Since every cron runs on a fresh database, on the first `run_crons`
every single cron in the db will run even though almost none of them
is relevant.

Aside from the slight inefficiency, this creates unnecessary extra
garbage in the test logs.

By setting the `nextcall` of all crons to infinity in the template we
avoid this issue, only triggered crons (or the crons whose nextcall we
set ourselves) will trigger during calls.

This requires adjusting the branch cleanup cron slightly: it didn't
correctly handle the initial run (`lastcall` being false).
This commit is contained in:
Xavier Morel 2024-08-05 08:03:56 +02:00
parent 157657af49
commit 78cc8835ce
2 changed files with 6 additions and 4 deletions

View File

@ -326,6 +326,7 @@ class DbDict(dict):
f.write(db)
f.flush()
os.fsync(f.fileno())
subprocess.run(['psql', db, '-c', "UPDATE ir_cron SET nextcall = 'infinity'"])
return db

View File

@ -9,10 +9,11 @@ class BranchCleanup(models.TransientModel):
_description = "cleans up scratch refs for deactivated branches"
def _run(self):
deactivated = self.env['runbot_merge.branch'].search([
('active', '=', False),
('write_date', '>=', self.env.context['lastcall']),
])
domain = [('active', '=', False)]
if lastcall := self.env.context['lastcall']:
domain.append(('write_date', '>=', lastcall))
deactivated = self.env['runbot_merge.branch'].search(domain)
_logger.info(
"deleting scratch (tmp and staging) refs for branches %s",
', '.join(b.name for b in deactivated)