Reschedule failing cron tasks progressively [MAILPOET-2181]

This commit is contained in:
wxa
2019-07-28 16:42:47 +03:00
committed by M. Shull
parent e1b8462254
commit 8b867a7b4f
9 changed files with 86 additions and 27 deletions

View File

@ -2,6 +2,7 @@
namespace MailPoet\Models;
use Carbon\Carbon;
use MailPoet\Util\Helpers;
use MailPoet\WP\Functions as WPFunctions;
@ -14,6 +15,7 @@ if (!defined('ABSPATH')) exit;
* @property string|null $type
* @property int $priority
* @property string|null $scheduled_at
* @property int $reschedule_count
* @property string|array|null $meta
*/
class ScheduledTask extends Model {
@ -26,6 +28,9 @@ class ScheduledTask extends Model {
const PRIORITY_MEDIUM = 5;
const PRIORITY_LOW = 10;
const BASIC_RESCHEDULE_TIMEOUT = 5; //minutes
const MAX_RESCHEDULE_TIMEOUT = 1440; //minutes
private $wp;
function __construct() {
@ -131,6 +136,16 @@ class ScheduledTask extends Model {
}
}
function rescheduleProgressively() {
$scheduled_at = Carbon::createFromTimestamp($this->wp->currentTime('timestamp'));
$timeout = min(self::BASIC_RESCHEDULE_TIMEOUT * pow(2, $this->reschedule_count), self::MAX_RESCHEDULE_TIMEOUT);
$this->scheduled_at = $scheduled_at->addMinutes($timeout);
$this->reschedule_count++;
$this->status = ScheduledTask::STATUS_SCHEDULED;
$this->save();
return $timeout;
}
static function touchAllByIds(array $ids) {
ScheduledTask::rawExecute(
'UPDATE `' . ScheduledTask::$_table . '`' .