Skip to content

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

@thomasplevy

Description

@thomasplevy

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...

Metadata

Metadata

Labels

Type: EnhancementImprovements existing features or code

Type

No type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions