Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion opensafely/jobrunner/executors/volumes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import importlib
import logging
import os
import shutil
import sys
import tempfile
Expand Down Expand Up @@ -57,10 +58,20 @@ def delete_volume(job):
docker.delete_volume(docker_volume_name(job))

def write_timestamp(job, path, timeout=None):
with tempfile.NamedTemporaryFile() as f:
try:
# Note: writing to the temporary file while there's already a handle open to it
# is fine on unix, but sometimes errors on Windows, so we can't use a context
# manager for opening and writing to the temp file here.
f = tempfile.NamedTemporaryFile(delete=False) # noqa: SIM115
f.close()
p = Path(f.name)
p.write_text(str(time.time_ns()))
docker.copy_to_volume(docker_volume_name(job), p, path, timeout)
finally:
try:
os.remove(f.name)
except Exception: # noqa: S110 (ruff wants us to log this)
pass

def read_timestamp(job, path, timeout=None):
return docker.read_timestamp(docker_volume_name(job), path, timeout)
Expand Down