Skip to content

Commit

Permalink
Merge pull request #64 from discoinfiltrator/master
Browse files Browse the repository at this point in the history
Force the nextrun calculation to use UTC to be consistent with the DB
  • Loading branch information
roborourke authored Sep 18, 2020
2 parents 8f27832 + 74006c5 commit 0d0b171
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions inc/class-job.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace HM\Cavalcade\Runner;

use DateInterval;
use DateTime;
use DateTimeZone;
use PDO;

const MYSQL_DATE_FORMAT = 'Y-m-d H:i:s';
Expand Down Expand Up @@ -81,8 +84,11 @@ public function mark_completed() {
}

public function reschedule() {
$this->nextrun = date( MYSQL_DATE_FORMAT, strtotime( $this->nextrun ) + $this->interval );
$this->status = 'waiting';
$date = new DateTime( $this->nextrun, new DateTimeZone( 'UTC' ) );
$date->add( new DateInterval( "PT{$this->interval}S" ) );
$this->nextrun = $date->format( MYSQL_DATE_FORMAT );

$this->status = 'waiting';

$query = "UPDATE {$this->table_prefix}cavalcade_jobs";
$query .= ' SET status = :status, nextrun = :nextrun';
Expand Down

0 comments on commit 0d0b171

Please sign in to comment.