From: Frank Brehm Date: Tue, 30 Apr 2019 09:08:42 +0000 (+0200) Subject: Starting with using locking on deploying X-Git-Tag: 1.6.4^2^2~3 X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=510d7d4cca4f3a5763dd6996cc94d7d46466d8dd;p=pixelpark%2Fpuppetmaster-webhooks.git Starting with using locking on deploying --- diff --git a/lib/webhooks/__init__.py b/lib/webhooks/__init__.py index 7e7f484..405ba9e 100644 --- a/lib/webhooks/__init__.py +++ b/lib/webhooks/__init__.py @@ -1,6 +1,6 @@ #!/bin/env python3 # -*- coding: utf-8 -*- -__version__ = '1.5.5' +__version__ = '1.6.1' # vim: ts=4 et list diff --git a/lib/webhooks/deploy.py b/lib/webhooks/deploy.py index cea6b47..5726aee 100644 --- a/lib/webhooks/deploy.py +++ b/lib/webhooks/deploy.py @@ -19,6 +19,7 @@ import pathlib # Own modules from fb_tools.common import pp +from fb_tools.handler.lock import LockHandler from . import __version__ @@ -44,6 +45,8 @@ class WebhookDeployApp(BaseHookApp): def __init__(self, appname=None, base_dir=None, verbose=0, version=__version__): """Constructor.""" + self.locker = None + description = _( 'Receives push events as JSON-Data and ' 'synchronizes the local repository.') @@ -91,6 +94,15 @@ class WebhookDeployApp(BaseHookApp): super(WebhookDeployApp, self).post_init() + self.locker = LockHandler( + appname=self.appname, verbose=self.verbose, base_dir=self.base_dir, + simulate=self.simulate, sudo=False, quiet=self.quiet, + lockretry_delay_start=0.5, lockretry_delay_increase=0.5, + lockretry_max_delay=30, max_lockfile_age=900, locking_use_pid=True, + lockdir='/tmp') + + self.locker.initialized = True + self.initialized = True # ------------------------------------------------------------------------- @@ -198,6 +210,10 @@ class WebhookDeployApp(BaseHookApp): if 'branch' in cfg and cfg['branch']: branch = cfg['branch'] + lockfile = 'deploy.' + pname + '.lock' + LOG.info(_("Trying to create lockfile {fn!r} in directory {d!r} ...").format( + fn=lockfile, d=str(self.locker.lockdir))) + LOG.info(_("Deploying working directory {f!r} for project {p!r} ...").format( f=full_path, p=full_name))