Skip to content

Commit

Permalink
Re-schedule with new recurrence when schedule changes
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Oct 13, 2021
1 parent f41681f commit 422d0f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/BackgroundTask/RecurringBackgroundTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ final public function schedule_event( ...$args ) {
}

$event_name = $this->get_event_name();
$timestamp = wp_next_scheduled( $event_name, $args );
$recurrence = $this->get_interval();

if ( $timestamp ) {
return;
}
$scheduled_event = wp_get_scheduled_event( $event_name, $args );

wp_schedule_event( time(), $this->get_interval(), $event_name, $args );
if ( $scheduled_event && $scheduled_event->schedule !== $recurrence ) {
wp_schedule_event( $scheduled_event->timestamp, $recurrence, $event_name, $args );
} elseif ( ! $scheduled_event ) {
wp_schedule_event( time(), $recurrence, $event_name, $args );
}
}

/**
Expand Down
2 changes: 0 additions & 2 deletions tests/php/src/Validation/URLValidationCronTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

namespace AmpProject\AmpWP\Tests\Validation;

use AmpProject\AmpWP\BackgroundTask\BackgroundTaskDeactivator;
use AmpProject\AmpWP\BackgroundTask\CronBasedBackgroundTask;
use AmpProject\AmpWP\Infrastructure\Registerable;
use AmpProject\AmpWP\Infrastructure\Service;
use AmpProject\AmpWP\Tests\DependencyInjectedTestCase;
use AmpProject\AmpWP\Tests\Helpers\PrivateAccess;
use AmpProject\AmpWP\Tests\Helpers\ValidationRequestMocking;
use AmpProject\AmpWP\Validation\ScannableURLProvider;
use AmpProject\AmpWP\Validation\URLScanningContext;
use AmpProject\AmpWP\Validation\URLValidationCron;

/** @coversDefaultClass \AmpProject\AmpWP\Validation\URLValidationCron */
Expand Down

0 comments on commit 422d0f2

Please sign in to comment.