mirror of
https://github.com/odoo/runbot.git
synced 2025-04-13 05:40:55 +07:00

`gc --prune` can not take a *separate* parameter, it has to be part of the same arg (the `=` is not optional), otherwise the `gc` call blows up. So use the positional form of the git command to generate the correct invocation, Python-level `foo=bar` generates a split-style option in two args which does not please git.
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
import logging
|
|
import subprocess
|
|
|
|
from odoo import models
|
|
from ...git import get_local
|
|
|
|
|
|
_gc = logging.getLogger(__name__)
|
|
class GC(models.TransientModel):
|
|
_name = 'runbot_merge.maintenance'
|
|
_description = "Weekly maintenance of... cache repos?"
|
|
|
|
def _run(self):
|
|
# lock out crons which use the local repo cache to avoid concurrency
|
|
# issues while we're GC-ing it
|
|
Stagings = self.env['runbot_merge.stagings']
|
|
crons = self.env.ref('runbot_merge.staging_cron', Stagings) | self.env.ref('forwardport.port_forward', Stagings)
|
|
if crons:
|
|
self.env.cr.execute("""
|
|
SELECT 1 FROM ir_cron
|
|
WHERE id = any(%s)
|
|
FOR UPDATE
|
|
""", [crons.ids])
|
|
|
|
# run on all repos with a forwardport target (~ forwardport enabled)
|
|
for repo in self.env['runbot_merge.repository'].search([]):
|
|
repo_git = get_local(repo, prefix=None)
|
|
if not repo_git:
|
|
continue
|
|
|
|
_gc.info('Running maintenance on %s', repo.name)
|
|
r = repo_git\
|
|
.stdout(True)\
|
|
.with_config(stderr=subprocess.STDOUT, text=True, check=False)\
|
|
.gc('--prune=now', aggressive=True)
|
|
if r.returncode:
|
|
_gc.warning("Maintenance failure (status=%d):\n%s", r.returncode, r.stdout)
|