Merge pull request #23484 from woocommerce/update/marketplace-queue-handling
Marketplace queue handling - avoid recurring event
This commit is contained in:
commit
036a91d20c
|
@ -188,12 +188,22 @@ class WC_Marketplace_Suggestions {
|
|||
}
|
||||
|
||||
/**
|
||||
* Pull suggestion data from remote endpoint & cache in a transient.
|
||||
* Pull suggestion data from options. This is retrieved from a remote endpoint.
|
||||
*
|
||||
* @return array of json API data
|
||||
*/
|
||||
public static function get_suggestions_api_data() {
|
||||
$data = get_option( 'woocommerce_marketplace_suggestions', array() );
|
||||
|
||||
// If the options have never been updated, or were updated over a week ago, queue update.
|
||||
if ( empty( $data['updated'] ) || ( time() - WEEK_IN_SECONDS ) > $data['updated'] ) {
|
||||
$next = WC()->queue()->get_next( 'woocommerce_update_marketplace_suggestions' );
|
||||
if ( ! $next ) {
|
||||
WC()->queue()->cancel_all( 'woocommerce_update_marketplace_suggestions' );
|
||||
WC()->queue()->schedule_single( time(), 'woocommerce_update_marketplace_suggestions' );
|
||||
}
|
||||
}
|
||||
|
||||
return ! empty( $data['suggestions'] ) ? $data['suggestions'] : array();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,12 +26,6 @@ class WC_Marketplace_Updater {
|
|||
* Schedule events and hook appropriate actions.
|
||||
*/
|
||||
public static function init() {
|
||||
$queue = WC()->queue();
|
||||
$next = $queue->get_next( 'woocommerce_update_marketplace_suggestions' );
|
||||
if ( ! $next ) {
|
||||
$queue->schedule_recurring( time(), WEEK_IN_SECONDS, 'woocommerce_update_marketplace_suggestions' );
|
||||
}
|
||||
|
||||
add_action( 'woocommerce_update_marketplace_suggestions', array( __CLASS__, 'update_marketplace_suggestions' ) );
|
||||
}
|
||||
|
||||
|
@ -78,7 +72,7 @@ class WC_Marketplace_Updater {
|
|||
* Re-schedules the job earlier than the main weekly one.
|
||||
*/
|
||||
public static function retry() {
|
||||
WC()->queue()->cancel( 'woocommerce_update_marketplace_suggestions' );
|
||||
WC()->queue()->cancel_all( 'woocommerce_update_marketplace_suggestions' );
|
||||
WC()->queue()->schedule_single( time() + DAY_IN_SECONDS, 'woocommerce_update_marketplace_suggestions' );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue