Skip to content
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

Add webhook failure email (and admin?) notice(s) #303

Open
thomasplevy opened this issue Nov 10, 2022 · 0 comments
Open

Add webhook failure email (and admin?) notice(s) #303

thomasplevy opened this issue Nov 10, 2022 · 0 comments
Assignees
Labels
Type: Enhancement Improvements existing features or code

Comments

@thomasplevy
Copy link
Contributor

If a webhook is disabled due to the maximum number of consecutive failures having been reached:

protected function set_delivery_failure() {
$failures = absint( $this->get( 'failure_count' ) );
$this->set( 'failure_count', ++$failures );
/**
* Filter the number of times a webhook is allowed to fail before it is automatically disabled.
*
* @since 1.0.0-beta.1
*
* @param int $num Number of allowed failures. Default: 5.
*/
$max_allowed = apply_filters( 'llms_rest_webhook_max_delivery_failures', 5 );
if ( $failures > $max_allowed ) {
$this->set( 'status', 'disabled' );
/**
* Fires immediately after a webhook has been disabled due to exceeding its maximum allowed failures.
*
* @since 1.0.0-beta.1
*
* @param int $webhook_id ID of the webhook.
*/
do_action( 'llms_rest_webhook_disabled_by_delivery_failures', $this->get( 'id' ) );
}
return $this;
}

There is currently no way for the admin to be aware of this other than proactively manually reviewing the webhooks list on the admin dashboard.

We should add an email notification that alerts users whenever a webhook fails. I think that creating this as a configurable email notification is probably best so that users can easily customize the behavior without code. Although the easiest solution might be to just make a simple email that can be customized with filters.

The notification should be sent to the webhook owner (and possibly to the site's main admin email address). Configuring this as an email notification makes it easy to add additional subscribers beyond the webhook owner too.

We could also pop an admin notice too?

This hook can be used to trigger:

do_action( 'llms_rest_webhook_disabled_by_delivery_failures', $this->get( 'id' ) );

But it would probably be better to actually create a new hook that triggers on every failure (not just on disabled).

Ideally, I think, a notification should be triggered after 2 failures: first failure might be a momentary interruption, second and beyond failures probably mean there's a problem...

@thomasplevy thomasplevy added the Type: Enhancement Improvements existing features or code label Nov 10, 2022
@thomasplevy thomasplevy moved this to Awaiting Triage in Development Nov 10, 2022
@thomasplevy thomasplevy moved this from Awaiting Triage to Backlog in Development Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improvements existing features or code
Projects
Status: Backlog
Development

No branches or pull requests

2 participants