Skip to content

Commit

Permalink
Make webhooks scheduled actions unique
Browse files Browse the repository at this point in the history
  • Loading branch information
thenbrent authored and mikejolley committed Jan 4, 2019
1 parent b924e36 commit 0593450
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions includes/wc-webhook-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ function wc_webhook_process_delivery( $webhook, $arg ) {
// so as to avoid delays or failures in delivery from affecting the
// user who triggered it.
if ( apply_filters( 'woocommerce_webhook_deliver_async', true, $webhook, $arg ) ) {
// Deliver in background.
WC()->queue()->add( 'woocommerce_deliver_webhook_async', array(
$queue_args = array(
'webhook_id' => $webhook->get_id(),
'arg' => $arg,
), 'woocommerce-webhooks' );
);

$next_scheduled_date = WC()->queue()->get_next( 'woocommerce_deliver_webhook_async', $queue_args, 'woocommerce-webhooks' );

// Make webhooks unique - only schedule one webhook every 10 minutes to maintain backward compatibility with WP Cron behaviour seen in WC < 3.5.0.
if ( is_null( $next_scheduled_date ) || $next_scheduled_date->getTimestamp() >= ( 600 + gmdate( 'U' ) ) ) {
WC()->queue()->add( 'woocommerce_deliver_webhook_async', $queue_args, 'woocommerce-webhooks' );
}
} else {
// Deliver immediately.
$webhook->deliver( $arg );
Expand Down

0 comments on commit 0593450

Please sign in to comment.