Skip to content

Commit

Permalink
feat(job): allow alternative worktimes beyond pyodide
Browse files Browse the repository at this point in the history
  • Loading branch information
wiwichips committed Aug 20, 2024
1 parent b64c96a commit ee6949f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions dcp/api/job.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"""
Job.
Wrapper class to get Bifrost2 API for the job.
Author: Severn Lortie <[email protected]>
Date: July 2024
"""
import pythonmonkey as pm
import cloudpickle
import dill
Expand Down Expand Up @@ -34,8 +42,9 @@ def __init__(self, job_js):
self.aio.wait = self._wait;

def _before_exec(self, *args, **kwargs):
# Any other worktime, do not apply serializers, env, jobfs
if not self.js_ref.worktime == "pyodide":
pass
return

work_function = urllib.parse.unquote(self.js_ref.workFunctionURI)
work_function = work_function.replace("data:,", "")
Expand Down Expand Up @@ -69,6 +78,7 @@ def _before_exec(self, *args, **kwargs):
serialized_arguments = self.js_ref.jobArguments
serialized_input_data = self.js_ref.jobInputData

# TODO don't copy to bytearray, use bytes directly
job_fs = bytearray(self.fs.to_gzip_tar())
env_args = convert_env_to_arguments(self.env)
modules = convert_modules_to_requires(self.modules)
Expand All @@ -80,7 +90,6 @@ def _before_exec(self, *args, **kwargs):
self.js_ref.jobArguments = [offset_to_argument_vector] + ["gzImage", job_fs] + env_args + serialized_arguments + [meta_arguments]
self.js_ref.workFunctionURI = "data:," + urllib.parse.quote(get_work_function_string(), safe="=:,#+;")

#TODO Make sure this runs on our event loop
def _exec(self, *args):

# TODO: remove once patched in DCP (TODO: link MR)
Expand All @@ -104,7 +113,6 @@ def handle_accepted():

return accepted_future

#TODO Make sure this runs on our event loop
def _wait(self):
if not self._exec_called:
raise Exception("Wait called before exec()")
Expand Down

0 comments on commit ee6949f

Please sign in to comment.