2012-02-27 17:11:25 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorMetaMTAWorker
|
|
|
|
extends PhabricatorWorker {
|
|
|
|
|
|
|
|
private $message;
|
|
|
|
|
2012-11-01 11:30:23 -07:00
|
|
|
public function getWaitBeforeRetry(PhabricatorWorkerTask $task) {
|
2012-11-01 16:38:47 -07:00
|
|
|
$message = $this->loadMessage();
|
|
|
|
if (!$message) {
|
2012-02-27 17:11:25 -08:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-11-01 16:38:47 -07:00
|
|
|
$wait = max($message->getNextRetry() - time(), 0) + 15;
|
2012-11-01 11:30:23 -07:00
|
|
|
return $wait;
|
2012-02-27 17:11:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function doWork() {
|
2012-11-01 16:38:47 -07:00
|
|
|
$message = $this->loadMessage();
|
2012-02-27 17:11:25 -08: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-01 16:38:47 -07: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-17 17:12:55 -08:00
|
|
|
public function renderForDisplay() {
|
2013-01-17 18:43:35 -08:00
|
|
|
return phutil_tag(
|
2013-08-29 17:37:17 -07:00
|
|
|
'pre',
|
|
|
|
array(
|
|
|
|
),
|
|
|
|
'phabricator/ $ ./bin/mail show-outbound --id '.$this->getTaskData());
|
2012-12-17 17:12:55 -08:00
|
|
|
}
|
|
|
|
|
2012-02-27 17:11:25 -08:00
|
|
|
}
|