Refactor ScheduledTasks::rescheduleProgressively() to use Doctrine

[MAILPOET-3844]
This commit is contained in:
Rodrigo Primo
2021-09-22 12:20:01 -03:00
committed by Veljko V
parent 82d4b8cb23
commit 2c78db9e04
14 changed files with 139 additions and 99 deletions

View File

@@ -30,8 +30,8 @@ class ScheduledTask extends Model {
const PRIORITY_MEDIUM = ScheduledTaskEntity::PRIORITY_MEDIUM;
const PRIORITY_LOW = ScheduledTaskEntity::PRIORITY_LOW;
const BASIC_RESCHEDULE_TIMEOUT = 5; //minutes
const MAX_RESCHEDULE_TIMEOUT = 1440; //minutes
const BASIC_RESCHEDULE_TIMEOUT = ScheduledTaskEntity::BASIC_RESCHEDULE_TIMEOUT;
const MAX_RESCHEDULE_TIMEOUT = ScheduledTaskEntity::MAX_RESCHEDULE_TIMEOUT;
private $wp;
@@ -130,16 +130,6 @@ class ScheduledTask extends Model {
return null;
}
public function rescheduleProgressively() {
$scheduledAt = Carbon::createFromTimestamp($this->wp->currentTime('timestamp'));
$timeout = (int)min(self::BASIC_RESCHEDULE_TIMEOUT * pow(2, $this->rescheduleCount), self::MAX_RESCHEDULE_TIMEOUT);
$this->scheduledAt = $scheduledAt->addMinutes($timeout);
$this->rescheduleCount++;
$this->status = ScheduledTask::STATUS_SCHEDULED;
$this->save();
return $timeout;
}
public static function touchAllByIds(array $ids) {
ScheduledTask::rawExecute(
'UPDATE `' . ScheduledTask::$_table . '`' .