Skip to content

Commit

Permalink
Merge pull request #73 from opengisch/shared_dirpath
Browse files Browse the repository at this point in the history
Get rid of host/qgis_tempdir confusion and use shared_tempdir only
  • Loading branch information
suricactus authored Sep 20, 2021
2 parents 4dfd9ae + e1af03e commit a999518
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
15 changes: 5 additions & 10 deletions docker-app/worker_wrapper/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@

logger = logging.getLogger(__name__)

TMP_DIRECTORY = os.environ.get("TMP_DIRECTORY", None)
QGIS_CONTAINER_NAME = os.environ.get("QGIS_CONTAINER_NAME", None)
QFIELDCLOUD_HOST = os.environ.get("QFIELDCLOUD_HOST", None)

assert TMP_DIRECTORY
assert QGIS_CONTAINER_NAME
assert QFIELDCLOUD_HOST

Expand All @@ -44,12 +42,9 @@ class JobRun:

def __init__(self, job_id: str) -> None:
try:
assert TMP_DIRECTORY

self.job_id = job_id
self.job = self.job_class.objects.select_related().get(id=job_id)
self.host_tempdir = Path(tempfile.mkdtemp(dir="/tmp"))
self.qgis_tempdir = Path(TMP_DIRECTORY).joinpath(self.host_tempdir)
self.shared_tempdir = Path(tempfile.mkdtemp(dir="/tmp"))
except Exception as err:
feedback = {}
(_type, _value, tb) = sys.exc_info()
Expand Down Expand Up @@ -100,15 +95,15 @@ def run(self):

command = self.get_command()
volumes = {}
volumes[str(self.qgis_tempdir)] = {"bind": "/io/", "mode": "rw"}
volumes[str(self.shared_tempdir)] = {"bind": "/io/", "mode": "rw"}

exit_code, output = self._run_docker(
command,
volumes=volumes,
)

try:
with open(self.host_tempdir.joinpath("feedback.json"), "r") as f:
with open(self.shared_tempdir.joinpath("feedback.json"), "r") as f:
feedback = json.load(f)

if feedback.get("error"):
Expand Down Expand Up @@ -272,7 +267,7 @@ def before_docker(self) -> None:

deltas.update(last_status=Delta.Status.STARTED)

with open(self.qgis_tempdir.joinpath("deltafile.json"), "w") as f:
with open(self.shared_tempdir.joinpath("deltafile.json"), "w") as f:
json.dump(deltafile_contents, f)

def after_docker(self) -> None:
Expand Down Expand Up @@ -313,7 +308,7 @@ class ProcessProjectfileJobRun(JobRun):
command = "process_projectfile %(project__id)s %(project__project_filename)s"

def after_docker(self) -> None:
thumbnail_filename = self.host_tempdir.joinpath("thumbnail.png")
thumbnail_filename = self.shared_tempdir.joinpath("thumbnail.png")
project = self.job.project

with open(thumbnail_filename, "rb") as f:
Expand Down
2 changes: 1 addition & 1 deletion docker-qgis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def logger_context(step: Step):
yield
step.stage = 2
finally:
print(f"::>>>::{log_uuid}", file=sys.stderr)
print(f"::>>>::{log_uuid} {step.stage}", file=sys.stderr)


def is_localhost(hostname: str, port: int = None) -> bool:
Expand Down

0 comments on commit a999518

Please sign in to comment.