]> Frank Brehm's Git Trees - pixelpark/puppetmaster-webhooks.git/commitdiff
Starting with using locking on deploying
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 30 Apr 2019 09:08:42 +0000 (11:08 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 30 Apr 2019 09:08:42 +0000 (11:08 +0200)
lib/webhooks/__init__.py
lib/webhooks/deploy.py

index 7e7f484776d2c39a9ab4a64360c4cc813edc968d..405ba9e0e3699b95278d6ccc912a50c72ee43e27 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/env python3
 # -*- coding: utf-8 -*-
 
-__version__ = '1.5.5'
+__version__ = '1.6.1'
 
 # vim: ts=4 et list
index cea6b478aad177971034d089a3158a587d4e12b3..5726aeebba96f7c03fa0cad56065e714d556575e 100644 (file)
@@ -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))