2012-02-28 02:11:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorMetaMTAWorker
|
|
|
|
extends PhabricatorWorker {
|
|
|
|
|
|
|
|
private $message;
|
|
|
|
|
2012-11-01 19:30:23 +01:00
|
|
|
public function getWaitBeforeRetry(PhabricatorWorkerTask $task) {
|
2012-11-02 00:38:47 +01:00
|
|
|
$message = $this->loadMessage();
|
|
|
|
if (!$message) {
|
2012-02-28 02:11:25 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-11-02 00:38:47 +01:00
|
|
|
$wait = max($message->getNextRetry() - time(), 0) + 15;
|
2012-11-01 19:30:23 +01:00
|
|
|
return $wait;
|
2012-02-28 02:11:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function doWork() {
|
2012-11-02 00:38:47 +01:00
|
|
|
$message = $this->loadMessage();
|
2012-02-28 02:11:25 +01:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
2012-11-02 00:38:47 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-12-18 02:12:55 +01:00
|
|
|
public function renderForDisplay() {
|
|
|
|
return phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array('href' => '/mail/view/'.$this->getTaskData().'/'),
|
|
|
|
phutil_escape_html($this->getTaskData()));
|
|
|
|
}
|
|
|
|
|
2012-02-28 02:11:25 +01:00
|
|
|
}
|