Skip to content

Commit

Permalink
The move data functionality did not previously update the database; n…
Browse files Browse the repository at this point in the history
…ow it does
  • Loading branch information
apdavison committed Jan 19, 2024
1 parent f4d10da commit 04d7ae7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
21 changes: 19 additions & 2 deletions api/simqueue/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ async def create_job_input_data_item(job_id, input_data):
return


async def update_job_output_data_item(job_id, output_data):
async def create_job_output_data_item(job_id, output_data):
for item in output_data:
ins_data_item = data_items.insert().values(**item)
data_item_id = await database.execute(ins_data_item)
Expand All @@ -258,6 +258,23 @@ async def update_job_output_data_item(job_id, output_data):
return


async def update_job_output_data_item(job_id, output_data):
for item in output_data:
if "hash" in item:
ins = (
data_items.update()
.where(
data_items.c.id == job_output_data.c.dataitem_id,
job_output_data.c.job_id == job_id,
data_items.c.hash == item["hash"],
)
.values(**item)
)
await database.execute(ins)
else:
raise ValueError("Modification of data items without hashes not yet implemented.")


async def update_log(job_id, log):
query = logs.select().where(logs.c.job_id == job_id)
result = await database.fetch_one(query)
Expand Down Expand Up @@ -392,7 +409,7 @@ async def update_job(job_id: int, job_patch: dict):
raise PostgresSyntaxError(f"job_patch was {job_patch}") from err

if output_data:
await update_job_output_data_item(job_id, output_data)
await create_job_output_data_item(job_id, output_data)
if log:
await update_log(job_id, log)
return await get_job(job_id)
Expand Down
7 changes: 6 additions & 1 deletion api/simqueue/resources/for_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ async def update_output_data(
)

try:
return original_dataset.move_to(
updated_dataset_result = original_dataset.move_to(
updated_dataset.repository, user, collab=job["collab_id"]
)
except ValueError as err: # requested repository does not exist
Expand All @@ -347,6 +347,11 @@ async def update_output_data(
except SourceFileDoesNotExist as err:
raise HTTPException(status_code=status_codes.HTTP_410_GONE, detail=str(err))

# now update the job
await db.update_job_output_data_item(job_id, updated_dataset_result.to_db())

return updated_dataset_result

raise HTTPException(
status_code=status_codes.HTTP_404_NOT_FOUND,
detail=f"Either there is no job with id {job_id}, or you do not have access to it",
Expand Down

0 comments on commit 04d7ae7

Please sign in to comment.