diff options
author | chivorotkiv <shmakov@omich.net> | 2015-05-02 11:16:36 +0600 |
---|---|---|
committer | chivorotkiv <shmakov@omich.net> | 2015-05-02 11:16:36 +0600 |
commit | 11d7b797624cec8bece0e776211faa1af68de5b4 (patch) | |
tree | 492e5093d698df82ad86d18f48c2d08fb284e076 /GitAutoDeploy.py | |
parent | 1e085259cd760156e0ca2bb43f29e6c00f493734 (diff) | |
download | Git-Auto-Deploy-11d7b797624cec8bece0e776211faa1af68de5b4.zip Git-Auto-Deploy-11d7b797624cec8bece0e776211faa1af68de5b4.tar.gz Git-Auto-Deploy-11d7b797624cec8bece0e776211faa1af68de5b4.tar.bz2 |
If deploy process is already running the second thread is waiting for finish and repeats deploy process. Third, fourth and all other threads see that some thread is waiting and do nothing just exit.
Diffstat (limited to 'GitAutoDeploy.py')
-rwxr-xr-x | GitAutoDeploy.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/GitAutoDeploy.py b/GitAutoDeploy.py index 1bc6ead..485d84f 100755 --- a/GitAutoDeploy.py +++ b/GitAutoDeploy.py @@ -47,8 +47,14 @@ class GitAutoDeploy(BaseHTTPRequestHandler): for url in urls: repos = self.getMatchingPaths(url) for repo in repos: - self.pull(repo['path'], repo['branch']) - self.deploy(repo['path']) + if self.lock(repo['path']): + try: + self.pull(repo['path'], repo['branch']) + self.deploy(repo['path']) + except: + call(['echo "Error during \'pull\' or \'deploy\' operation on path: ' + repo['path'] + '"'], shell=True) + finally: + self.unlock(repo['path']) def parseRequest(self): contenttype = self.headers.getheader('content-type') @@ -111,11 +117,19 @@ class GitAutoDeploy(BaseHTTPRequestHandler): self.send_header('Content-type', 'text/plain') self.end_headers() + def lock(self, path): + return 0 == call(['sh lock.sh "' + path + '"'], shell=True) + + def unlock(self, path): + call(['sh unlock.sh "' + path + '"'], shell=True) + def pull(self, path, branch): if(not self.quiet): print "\nPost push request received" print 'Updating ' + path - call(['cd "' + path + '" && git fetch origin ; git update-index --refresh &> /dev/null ; git reset --hard origin/' + branch], shell=True) + res = call(['cd "' + path + '" && git fetch origin ; git update-index --refresh &> /dev/null ; git reset --hard origin/' + branch], shell=True) + call(['echo "Pull result: ' + str(res) + '"'], shell=True) + return res def deploy(self, path): config = self.getConfig() |