Skip to content

Conversation

stktyagi
Copy link
Member

@stktyagi stktyagi commented Aug 1, 2025

Extracted send_api_task_notification, handle_error_notification and handle_recovery_notification helpers from existing code to send error/recovery messages via generic notifications. Updated trigger_vpn_server_endpoint
to use this mechanism for better observability of failures.

Closes #1049

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • I have updated the documentation.

Reference to Existing Issue

Closes #1049.

…1049

Added `send_api_task_notification`, `handle_error_notification` and `handle_recovery_notification`
helpers to send error/recovery messages via generic notifications.
Updated `trigger_vpn_server_endpoint`
to use this mechanism for better observability of failures.

Fixes #1049
@coveralls
Copy link

coveralls commented Aug 1, 2025

Coverage Status

coverage: 98.73% (-0.03%) from 98.759%
when pulling 108e66c on issues/1049-send-generic-message
into 3a45fd9 on master.

Copy link
Member

@nemesifier nemesifier left a 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)
Copy link
Member

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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)
Copy link
Member

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)
Copy link
Member

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):
Copy link
Member

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.

Copy link
Member Author

@stktyagi stktyagi Aug 16, 2025

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -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(
Copy link
Member

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.

stktyagi and others added 2 commits August 23, 2025 01:46
…1049

Replaced direct calls to send_api_task_notification in
trigger_vpn_server_endpoint with handle_error_notification and handle_recovery_notification.

Fixes #1049
@nemesifier nemesifier moved this to In progress in 25.09 Release Sep 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In progress
Status: To do (general)
Development

Successfully merging this pull request may close these issues.

[change] Send generic_message on trigger_vpn_server_endpoint errors
3 participants