Reschedule bounce task

[MAILPOET-2100]
This commit is contained in:
Pavel Dohnal
2019-06-06 16:34:33 +02:00
committed by M. Shull
parent 7163ee6430
commit e1e96d0c12
3 changed files with 50 additions and 0 deletions

View File

@ -122,6 +122,7 @@ class Scheduler {
'post notification set status to sending',
['newsletter_id' => $newsletter->id, 'task_id' => $queue->task_id]
);
$this->reScheduleBounceTask();
return true;
}
@ -158,6 +159,7 @@ class Scheduler {
$task->save();
// update newsletter status
$newsletter->setStatus(Newsletter::STATUS_SENDING);
$this->reScheduleBounceTask();
return true;
}
@ -233,6 +235,18 @@ class Scheduler {
ScheduledTask::touchAllByIds($ids);
}
private function reScheduleBounceTask() {
$bounce_tasks = Bounce::getScheduledTasks($future = true);
if (count($bounce_tasks)) {
$bounce_task = reset($bounce_tasks);
if (Carbon::createFromTimestamp(current_time('timestamp'))->addHour(42)->lessThan($bounce_task->scheduled_at)) {
$random_offset = rand(-6 * 60 * 60, 6 * 60 * 60);
$bounce_task->scheduled_at = Carbon::createFromTimestamp(current_time('timestamp'))->addSecond((36 * 60 * 60) + $random_offset);
$bounce_task->save();
}
}
}
static function getScheduledQueues() {
return SendingTask::getScheduledQueues(self::TASK_BATCH_SIZE);
}

View File

@ -125,6 +125,10 @@ abstract class SimpleWorker {
return $date;
}
/**
* @param bool $future
* @return ScheduledTask[]
*/
static function getScheduledTasks($future = false) {
$dateWhere = ($future) ? 'whereGt' : 'whereLte';
$wp = new WPFunctions();