1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-11 17:32:41 +01:00
phorge-phorge/src/applications/metamta/PhabricatorMetaMTAWorker.php

52 lines
1.2 KiB
PHP
Raw Normal View History

<?php
final class PhabricatorMetaMTAWorker
extends PhabricatorWorker {
private $message;
public function getWaitBeforeRetry(PhabricatorWorkerTask $task) {
$message = $this->loadMessage();
if (!$message) {
return null;
}
$wait = max($message->getNextRetry() - time(), 0) + 15;
return $wait;
}
public function doWork() {
$message = $this->loadMessage();
if (!$message
|| $message->getStatus() != PhabricatorMetaMTAMail::STATUS_QUEUE) {
return;
}
$id = $message->getID();
$message->sendNow();
// task failed if the message is still queued
// (instead of sent, void, or failed)
if ($message->getStatus() == PhabricatorMetaMTAMail::STATUS_QUEUE) {
throw new Exception('Failed to send message');
}
}
private function loadMessage() {
if (!$this->message) {
$message_id = $this->getTaskData();
$this->message = id(new PhabricatorMetaMTAMail())->load($message_id);
if (!$this->message) {
return null;
}
}
return $this->message;
}
public function renderForDisplay() {
return phutil_render_tag(
'a',
array('href' => '/mail/view/'.$this->getTaskData().'/'),
phutil_escape_html($this->getTaskData()));
}
}