Skip to content

Commit

Permalink
Factor out notification call into methods
Browse files Browse the repository at this point in the history
This increases reusability by other managers

Thanks @ricardogsilva !
  • Loading branch information
totycro committed Mar 6, 2024
1 parent 5124dd9 commit feed719
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions pygeoapi/process/manager/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,7 @@ def _execute_handler_sync(self, p: BaseProcessor, job_id: str,
}

self.add_job(job_metadata)
if subscriber and subscriber.in_progress_uri:
response = requests.post(subscriber.in_progress_uri, json={})
LOGGER.debug(
'In progress notification response: {response.status_code}'
)
self._send_in_progress_notification(subscriber)

try:
if self.output_dir is not None:
Expand Down Expand Up @@ -287,12 +283,7 @@ def _execute_handler_sync(self, p: BaseProcessor, job_id: str,
}

self.update_job(job_id, job_update_metadata)

if subscriber:
response = requests.post(subscriber.success_uri, json=outputs)
LOGGER.debug(
f'Success notification response: {response.status_code}'
)
self._send_success_notification(subscriber, outputs=outputs)

except Exception as err:
# TODO assess correct exception type and description to help users
Expand Down Expand Up @@ -324,11 +315,7 @@ def _execute_handler_sync(self, p: BaseProcessor, job_id: str,

self.update_job(job_id, job_metadata)

if subscriber and subscriber.failed_uri:
response = requests.post(subscriber.failed_uri, json={})
LOGGER.debug(
f'Failed notification response: {response.status_code}'
)
self._send_failed_notification(subscriber)

return jfmt, outputs, current_status

Expand Down Expand Up @@ -401,6 +388,29 @@ def execute_process(
)
return job_id, mime_type, outputs, status, response_headers

def _send_in_progress_notification(self, subscriber: Optional[Subscriber]):
if subscriber and subscriber.in_progress_uri:
response = requests.post(subscriber.in_progress_uri, json={})
LOGGER.debug(
f'In progress notification response: {response.status_code}'
)

def _send_success_notification(
self, subscriber: Optional[Subscriber], outputs: Any
):
if subscriber:
response = requests.post(subscriber.success_uri, json=outputs)
LOGGER.debug(
f'Success notification response: {response.status_code}'
)

def _send_failed_notification(self, subscriber: Optional[Subscriber]):
if subscriber and subscriber.failed_uri:
response = requests.post(subscriber.failed_uri, json={})
LOGGER.debug(
f'Failed notification response: {response.status_code}'
)

def __repr__(self):
return f'<BaseManager> {self.name}'

Expand Down

0 comments on commit feed719

Please sign in to comment.