summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-03-14 23:22:22 +0000
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-03-27 11:53:02 +0000
commit515b918e2681583a60bb870da070b054406a10d8 (patch)
tree36773334e18785e653c1605f36bd6736e4a88835
parentb91778ae05e51d4b15e49192347c25d1935e7408 (diff)
downloadmorph-515b918e2681583a60bb870da070b054406a10d8.tar.gz
Atomic upload artifacts
Change-Id: Ic48575151209d313367153d4fbee1b6679c17248
-rw-r--r--gear/worker.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/gear/worker.py b/gear/worker.py
index f7cb9d28..e8abacda 100644
--- a/gear/worker.py
+++ b/gear/worker.py
@@ -43,16 +43,17 @@ def upload_files(cache_key, suffixes):
sftp = client.open_sftp()
for single_file in files_to_upload:
remote_dest = os.path.join(remote_cache_dir, os.path.basename(single_file))
+ remote_dest_tmp = os.path.join(remote_cache_dir, os.path.basename(single_file) + '.tmp')
print "DEBUG: going to upload %s" % single_file
print "DEBUG: upload destination %s" % remote_dest
- # TODO: atomic upload!! sftp.rename(remotePath+'/tmp/'+fileName, remotePath+fileName)
try:
sftp.stat(remote_dest)
print "DEBUG: file already exists"
return
except:
print "DEBUG: file not found in cache, uploading"
- sftp.put(single_file, remote_dest)
+ sftp.put(single_file, remote_dest_tmp)
+ sftp.rename(remote_dest_tmp, remote_dest)
while True:
print "DEBUG: Waiting for job"