Skip to content

Commit

Permalink
update to worker for simularium io fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed Aug 16, 2024
1 parent 4b743ed commit 52da5b0
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
2 changes: 1 addition & 1 deletion compose_worker/.CONTAINER_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.1
1.2.2
2 changes: 1 addition & 1 deletion compose_worker/io_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async def save_uploaded_file(uploaded_file: UploadFile | str, save_dest: str) ->
file.write(contents)
# case: is a string
else:
with open(uploaded_file, 'r') as fp:
with open(filename, 'r') as fp:
contents = fp.read()
with open(file_path, 'w') as f:
f.write(contents)
Expand Down
72 changes: 71 additions & 1 deletion compose_worker/test.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,83 @@
],
"execution_count": 14
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-16T16:27:53.329449Z",
"start_time": "2024-08-16T16:27:53.324343Z"
}
},
"cell_type": "code",
"source": "job = {'status': 'PENDING', 'job_id': 'files-generate-simularium-file00f049df-3211-469c-b009-1c95aae5dc11', 'timestamp': '2024-08-16 16:09:28.578099', 'path': 'uploads/files-generate-simularium-file00f049df-3211-469c-b009-1c95aae5dc11/modelout.txt', 'filename': 'simulation', 'box_size': 10.0}",
"id": "e28c150926800fd6",
"outputs": [],
"execution_count": 1
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-16T16:27:55.662239Z",
"start_time": "2024-08-16T16:27:53.525441Z"
}
},
"cell_type": "code",
"source": [
"from workers import FilesWorker\n",
"\n",
"worker = FilesWorker(job)"
],
"id": "436b54da8b148037",
"outputs": [],
"execution_count": 2
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2024-08-16T16:27:59.482241Z",
"start_time": "2024-08-16T16:27:55.663211Z"
}
},
"cell_type": "code",
"source": [
"from asyncio import run \n",
"\n",
"await worker.run()"
],
"id": "49e481a5ae875ac2",
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/var/folders/yy/8crj8x7x5_3b86f0js6_0bn00000gr/T/tmp4fkcjh7t/modelout.txt\n",
"Reading Smoldyn Data -------------\n",
"Filtering: translation -------------\n",
"Converting Trajectory Data to JSON -------------\n",
"Writing JSON -------------\n",
"saved to /var/folders/yy/8crj8x7x5_3b86f0js6_0bn00000gr/T/tmp4fkcjh7t/modelouttxt-simulation.simularium\n"
]
},
{
"data": {
"text/plain": [
"{'results': {'results_file': 'uploads/files-generate-simularium-file00f049df-3211-469c-b009-1c95aae5dc11/modelouttxt-simulation.simularium'}}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 3
},
{
"metadata": {},
"cell_type": "code",
"outputs": [],
"execution_count": null,
"source": "",
"id": "e28c150926800fd6"
"id": "9920ec3288a1bd56"
}
],
"metadata": {
Expand Down
6 changes: 4 additions & 2 deletions compose_worker/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ async def run(self):
if input_path is not None:
# download the input file
dest = tempfile.mkdtemp()
local_input_path = await download_file(source_blob_path=input_path, bucket_name=BUCKET_NAME, out_dir=dest)

local_input_path = download_file(source_blob_path=input_path, bucket_name=BUCKET_NAME, out_dir=dest)
print(local_input_path)
# case: is a smoldyn output file and thus a simularium job
if input_path.endswith('.txt'):
await self._run_simularium(job_id=job_id, input_path=local_input_path, dest=dest)
Expand All @@ -493,6 +493,8 @@ async def _run_simularium(self, job_id: str, input_path: str, dest: str):
results_file = result.get('simularium_file')
uploaded_file_location = None
if results_file is not None:
if not results_file.endswith('.simularium'):
results_file += '.simularium'
uploaded_file_location = await write_uploaded_file(job_id=job_id, bucket_name=BUCKET_NAME, uploaded_file=results_file, extension='.simularium')

self.job_result['results'] = {'results_file': uploaded_file_location}
Expand Down

0 comments on commit 52da5b0

Please sign in to comment.