generated from NASA-AMMOS/slim-starterkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add action to submit HySDS job for NISAR ECMWF task (#5)
* initial implementation of HySDS submit job action * fix schema * finalize implementation; add unit and regression tests
- Loading branch information
Showing
5 changed files
with
148 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import json | ||
import uuid | ||
|
||
import httpx | ||
|
||
from ..utils.logger import logger | ||
from .base import Action | ||
|
||
__all__ = ["SubmitHysdsJob"] | ||
|
||
|
||
class SubmitHysdsJob(Action): | ||
def __init__(self, payload, payload_info, params): | ||
super().__init__(payload, payload_info, params) | ||
logger.info("instantiated %s", __class__.__name__) | ||
|
||
def execute(self): | ||
"""Submit job to mozart via REST API.""" | ||
|
||
# build job params | ||
job_params = { | ||
"payload": self._payload, | ||
"payload_info": self._payload_info, | ||
"on_success": self._params["on_success"], | ||
} | ||
|
||
# setup url and request body | ||
url = self._params["mozart_base_api_endpoint"] | ||
body = { | ||
"queue": self._params["queue"], | ||
"priority": self._params.get("priority", 0), | ||
"tags": json.dumps(self._params.get("tags", [])), | ||
"type": self._params["job_spec"], | ||
"params": json.dumps(job_params), | ||
"name": f"{self._params['job_spec'].split(':')[0]}-{str(uuid.uuid4())}", | ||
} | ||
|
||
# submit job | ||
logger.info("job URL: %s", url) | ||
logger.info("job params: %s", json.dumps(body, indent=2, sort_keys=True)) | ||
response = httpx.post(url, data=body, verify=False) # nosec | ||
if response.status_code in (200, 201): | ||
success = True | ||
resp = response.json() | ||
logger.info( | ||
"Successfully submitted HySDS job %s: %s", | ||
self._params["job_spec"], | ||
resp, | ||
) | ||
else: | ||
success = False | ||
resp = response.text | ||
logger.info( | ||
"Failed to submit HySDS job %s: %s", self._params["job_spec"], resp | ||
) | ||
return {"success": success, "response": resp} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters