Skip to content

Setup webhook automatic retries #302

@thomasplevy

Description

@thomasplevy

Currently our webhooks are set to track failed attempts and automatically disable after 5 failed delivery attempts:

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;
}

This would require 5 separate deliveries for 5 events though. EG: if it's triggered during student enrollment, the webhook will disable after the 5th student fails enrollment.

This is problematic if an external application relies on webhook deliveries to maintain data integrity in the external application.

We should automatically reschedule a failed webhook delivery on a delay (5-15 minutes? Possibly it should track individual event failures and increase the delay: failure 1, wait 5 minutes, resend; failure 2 wait 30 minutes and resend; etc...)

After failure, we can check whether the webhook should be disabled and, if not, we can reschedule it using the same args passed into the deliver() method:

public function deliver( $args ) {

In order to best track failures for the specific event we could probably just add an extra argument to the args array:

$args['retry_count'] ?? 0;
++$args['retry_count;

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