Skip to content

Commit

Permalink
fix--from-spec
Browse files Browse the repository at this point in the history
  • Loading branch information
luiztauffer committed Oct 26, 2023
1 parent 0a695f9 commit b5d34bc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
10 changes: 7 additions & 3 deletions python/protocaas/compute_resource/start_compute_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def __init__(self):
'spec': spec
}
)

print('Getting pubsub info')
pubsub_subscription = get_pubsub_subscription(
compute_resource_id=self._compute_resource_id,
Expand All @@ -84,6 +83,7 @@ def __init__(self):
)
else:
self._pubsub_client = None

def start(self, *, timeout: Optional[float] = None, cleanup_old_jobs=True): # timeout is used for testing
timer_handle_jobs = 0

Expand Down Expand Up @@ -120,6 +120,7 @@ def start(self, *, timeout: Optional[float] = None, cleanup_old_jobs=True): # ti
time.sleep(0.01) # for the first few seconds we can sleep for a short time (useful for testing)
else:
time.sleep(2)

def _handle_jobs(self):
url_path = f'/api/compute_resource/compute_resources/{self._compute_resource_id}/unfinished_jobs'
if not self._compute_resource_id:
Expand Down Expand Up @@ -170,14 +171,19 @@ def _get_job_resource_type(self, job: ProtocaasJob) -> Union[str, None]:
if app._slurm_opts is not None:
return 'slurm'
return 'local'

def _is_local_job(self, job: ProtocaasJob) -> bool:
return self._get_job_resource_type(job) == 'local'

def _is_aws_batch_job(self, job: ProtocaasJob) -> bool:
return self._get_job_resource_type(job) == 'aws_batch'

def _is_slurm_job(self, job: ProtocaasJob) -> bool:
return self._get_job_resource_type(job) == 'slurm'

def _job_is_pending(self, job: ProtocaasJob) -> bool:
return job.status == 'pending'

def _start_job(self, job: ProtocaasJob, run_process: bool = True, return_shell_command: bool = False):
job_id = job.jobId
if job_id in self._attempted_to_start_job_ids:
Expand Down Expand Up @@ -274,7 +280,6 @@ def _load_apps(*, compute_resource_id: str, compute_resource_private_key: str, c

def start_compute_resource(dir: str, *, timeout: Optional[float] = None, cleanup_old_jobs=True): # timeout is used for testing
config_fname = os.path.join(dir, '.protocaas-compute-resource-node.yaml')

if os.path.exists(config_fname):
with open(config_fname, 'r', encoding='utf8') as f:
the_config = yaml.safe_load(f)
Expand All @@ -283,7 +288,6 @@ def start_compute_resource(dir: str, *, timeout: Optional[float] = None, cleanup
for k in env_var_keys:
if k in the_config:
os.environ[k] = the_config[k]

daemon = Daemon()
daemon.start(timeout=timeout, cleanup_old_jobs=cleanup_old_jobs)

Expand Down
15 changes: 11 additions & 4 deletions python/protocaas/sdk/App.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ class ProtocaasAppException(Exception):

class App:
"""An app"""
def __init__(self, name: str, *, help: str, app_image: Union[str, None] = None, app_executable: Union[str, None] = None) -> None:
def __init__(
self,
name: str,
*,
help: str,
app_image: Union[str, None] = None,
app_executable: Union[str, None] = None
) -> None:
"""Construct a new Protocaas App
Args:
Expand Down Expand Up @@ -106,7 +113,9 @@ def from_spec(spec):
"""Define an app from a spec. This is called internally."""
app = App(
name=spec['name'],
help=spec['help']
help=spec['help'],
app_image=spec.get('appImage', None),
app_executable=spec.get('appExecutable', None)
)
for processor_spec in spec['processors']:
processor = AppProcessor.from_spec(processor_spec)
Expand All @@ -123,8 +132,6 @@ def from_spec_uri(
"""Define an app from a spec URI (e.g., a gh url to the spec.json blob). This is called internally."""
spec: dict = _load_spec_from_uri(spec_uri)
a = App.from_spec(spec)
setattr(a, '_app_image', spec.get('appImage', None))
setattr(a, "_app_executable", spec.get('appExecutable', None))
setattr(a, "_aws_batch_job_queue", aws_batch_job_queue)
setattr(a, "_aws_batch_job_definition", aws_batch_job_definition)
setattr(a, "_slurm_opts", slurm_opts)
Expand Down

0 comments on commit b5d34bc

Please sign in to comment.