mirror of
https://github.com/odoo/runbot.git
synced 2025-03-27 13:25:47 +07:00
[IMP] runbot: git gc only once a day
This commit is contained in:
parent
c006bf953d
commit
d027d1c7de
@ -26,7 +26,6 @@ class RunbotClient():
|
|||||||
self.host = None
|
self.host = None
|
||||||
self.count = 0
|
self.count = 0
|
||||||
self.max_count = 60
|
self.max_count = 60
|
||||||
self.next_git_gc_date = datetime.now() + timedelta(minutes=random.randint(5, 15))
|
|
||||||
|
|
||||||
def on_start(self):
|
def on_start(self):
|
||||||
pass
|
pass
|
||||||
@ -38,6 +37,7 @@ class RunbotClient():
|
|||||||
signal.signal(signal.SIGTERM, self.signal_handler)
|
signal.signal(signal.SIGTERM, self.signal_handler)
|
||||||
signal.signal(signal.SIGQUIT, self.dump_stack)
|
signal.signal(signal.SIGQUIT, self.dump_stack)
|
||||||
self.host = self.env['runbot.host']._get_current()
|
self.host = self.env['runbot.host']._get_current()
|
||||||
|
self.update_next_git_gc_date()
|
||||||
self.host._bootstrap()
|
self.host._bootstrap()
|
||||||
logging.info(
|
logging.info(
|
||||||
'Host %s running with %s slots on pid %s%s',
|
'Host %s running with %s slots on pid %s%s',
|
||||||
@ -83,13 +83,21 @@ class RunbotClient():
|
|||||||
def sleep(self, t):
|
def sleep(self, t):
|
||||||
self.ask_interrupt.wait(t)
|
self.ask_interrupt.wait(t)
|
||||||
|
|
||||||
|
def update_next_git_gc_date(self):
|
||||||
|
now = datetime.now()
|
||||||
|
gc_hour = int(self.env['ir.config_parameter'].sudo().get_param('runbot.git_gc_hour', '23'))
|
||||||
|
gc_minutes = self.host.id % 60 # deterministic minutes
|
||||||
|
self.next_git_gc_date = datetime(now.year, now.month, now.day, gc_hour, gc_minutes)
|
||||||
|
while self.next_git_gc_date <= now:
|
||||||
|
self.next_git_gc_date += timedelta(days=1)
|
||||||
|
_logger.info('Next git gc scheduled on %s', self.next_git_gc_date)
|
||||||
|
|
||||||
def git_gc(self):
|
def git_gc(self):
|
||||||
""" git gc once a day """
|
""" git gc once a day """
|
||||||
if datetime.now() > self.next_git_gc_date:
|
if self.next_git_gc_date < datetime.now():
|
||||||
_logger.info('Starting git gc on repositories')
|
_logger.info('Starting git gc on repositories')
|
||||||
self.env['runbot.runbot']._git_gc(self.host)
|
self.env['runbot.runbot']._git_gc(self.host)
|
||||||
self.next_git_gc_date = datetime.now() + timedelta(hours=2, minutes=random.randint(0, 59))
|
self.update_next_git_gc_date()
|
||||||
_logger.info('Next git gc scheduled on %s', self.next_git_gc_date)
|
|
||||||
|
|
||||||
def run(client_class):
|
def run(client_class):
|
||||||
# parse args
|
# parse args
|
||||||
@ -135,5 +143,9 @@ def run(client_class):
|
|||||||
env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {})
|
env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {})
|
||||||
client = client_class(env)
|
client = client_class(env)
|
||||||
# run main loop
|
# run main loop
|
||||||
client.main_loop()
|
try:
|
||||||
|
client.main_loop()
|
||||||
|
except Exception as e:
|
||||||
|
_logger.exception(str(e))
|
||||||
|
raise e
|
||||||
_logger.info("Stopping gracefully")
|
_logger.info("Stopping gracefully")
|
||||||
|
Loading…
Reference in New Issue
Block a user