-
-
Notifications
You must be signed in to change notification settings - Fork 226
[change] Update trigger_vpn_server_endpoint to send generic_message #… #1104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good progress @stktyagi, see my comments below.
# of the django success message container | ||
# with the ow-notification container | ||
# https://github.com/openwisp/openwisp-notifications/issues/264 | ||
sleep(2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be optional. Eg:
if snooze:
sleep(snooze)
@@ -206,3 +210,60 @@ def get_default_templates_queryset( | |||
def get_config_error_notification_target_url(obj, field, absolute_url=True): | |||
url = _get_object_link(obj._related_object(field), absolute_url) | |||
return f"{url}#config-group" | |||
|
|||
|
|||
def send_api_task_notification(type, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def send_api_task_notification(type, **kwargs): | |
def send_api_task_notification(type, snooze=None, **kwargs): |
if task_result == "error": | ||
self._send_api_task_notification("recovery", **kwargs) | ||
cache.set(task_key, "success", None) | ||
handle_recovery_notification(task_key, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass in snooze=2 here
self._send_api_task_notification( | ||
"error", status_code=response.status_code, **kwargs | ||
) | ||
handle_error_notification(task_key, response, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pass in snooze=2 here
) | ||
|
||
|
||
def handle_recovery_notification(task_key, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we extracting this logic here if we aren't reusing it for trigger_vpn_server_endpoint
? What's the point of this work? We don't do changes for the sake of it. There's no advantage in exctracting this heare if we don't reuse it as discussed initially.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this is something that can be used and would be needed to be exposed in future and looks cleaner. Just as we thought _send_api_task_notification wasn't meant to be exposed separately initially but as we see it had to be.
I can undo those 2 functions back where they were and it won't affect the current implementation but I think they also follow the utility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1104 (comment).
openwisp_controller/config/tasks.py
Outdated
@@ -121,6 +123,12 @@ def trigger_vpn_server_endpoint(endpoint, auth_token, vpn_id): | |||
f"Response status code: {response.status_code}, " | |||
f"VPN Server UUID: {vpn_id}", | |||
) | |||
send_api_task_notification( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was expecting handle_error_notification
and handle_recovery_notification
to be used in this function.
We'll need to update existing tests to assert these are being executed as expected.
Extracted
send_api_task_notification
,handle_error_notification
andhandle_recovery_notification
helpers from existing code to send error/recovery messages via generic notifications. Updatedtrigger_vpn_server_endpoint
to use this mechanism for better observability of failures.
Closes #1049
Checklist
Reference to Existing Issue
Closes #1049.