runbot/runbot_builder/builder.py
Christophe Monniez 250d48e266 [IMP] runbot: schedule git gc on repositories
On the actual runbot deployments, the `git gc` command is handled by a
unix cron. From time to time, some repositories get corrupted and we
suspect that some concurrent action may be involved as stated in
documentation [0].

For those reasons, with this commit, the `git gc` will be run by the
runbot clients themselves in order to avoid concurrent operations.

By default, the first gc will occur a few minutes after the start of the
client and the next gc are scheduled a two hours and a few minutes later.

Also, this commit ensures that the git config is written regularly in
case of change.

[0] https://git-scm.com/docs/git-gc
2022-06-20 10:32:10 +02:00

27 lines
829 B
Python
Executable File

#!/usr/bin/python3
from tools import RunbotClient, run
import logging
_logger = logging.getLogger(__name__)
class BuilderClient(RunbotClient):
def on_start(self):
for repo in self.env['runbot.repo'].search([('mode', '!=', 'disabled')]):
repo._update(force=True)
def loop_turn(self):
if self.count == 1: # cleanup at second iteration
self.env['runbot.runbot']._source_cleanup()
self.env['runbot.build']._local_cleanup()
self.env['runbot.runbot']._docker_cleanup()
self.host.set_psql_conn_count()
self.host._docker_build()
self.env['runbot.repo']._update_git_config()
self.git_gc()
return self.env['runbot.runbot']._scheduler_loop_turn(self.host)
if __name__ == '__main__':
run(BuilderClient)