Skip to content

Commit d57f07e

Browse files
committed
Extract provisioning tasks
1 parent b37f0e7 commit d57f07e

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

  • app/grandchallenge/components/backends

app/grandchallenge/components/backends/base.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -370,19 +370,7 @@ def _provision_inputs(self, *, input_civs, input_prefixes):
370370
civ=civ, input_prefixes=input_prefixes
371371
)
372372

373-
if civ.image:
374-
self._copy_input_file(src=civ.image_file, dest_key=key)
375-
elif civ.file:
376-
self._copy_input_file(src=civ.file, dest_key=key)
377-
else:
378-
with io.BytesIO() as f:
379-
f.write(json.dumps(civ.value).encode("utf-8"))
380-
f.seek(0)
381-
self._s3_client.upload_fileobj(
382-
Fileobj=f,
383-
Bucket=settings.COMPONENTS_INPUT_BUCKET_NAME,
384-
Key=key,
385-
)
373+
self._get_provisioning_tasks(civ, key)
386374

387375
invocation_inputs.append(
388376
{
@@ -395,6 +383,25 @@ def _provision_inputs(self, *, input_civs, input_prefixes):
395383

396384
self._create_invocation_json(inputs=invocation_inputs)
397385

386+
def _get_provisioning_tasks(self, civ, key):
387+
if civ.interface.super_kind == civ.interface.SuperKind.IMAGE:
388+
self._copy_input_file(src=civ.image_file, dest_key=key)
389+
elif civ.interface.super_kind == civ.interface.SuperKind.FILE:
390+
self._copy_input_file(src=civ.file, dest_key=key)
391+
elif civ.interface.super_kind == civ.interface.SuperKind.VALUE:
392+
with io.BytesIO() as f:
393+
f.write(json.dumps(civ.value).encode("utf-8"))
394+
f.seek(0)
395+
self._s3_client.upload_fileobj(
396+
Fileobj=f,
397+
Bucket=settings.COMPONENTS_INPUT_BUCKET_NAME,
398+
Key=key,
399+
)
400+
else:
401+
raise NotImplementedError(
402+
f"Unknown interface super kind: {civ.interface.super_kind}"
403+
)
404+
398405
def _with_inputs_json(self, *, input_civs):
399406
"""
400407
An iterator over all inputs along with the special inputs.json,

0 commit comments

Comments
 (0)