2012-02-27 17:11:25 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorMetaMTAWorker
|
|
|
|
extends PhabricatorWorker {
|
|
|
|
|
2014-02-01 14:35:42 -08:00
|
|
|
public function getMaximumRetryCount() {
|
|
|
|
return 250;
|
|
|
|
}
|
2012-02-27 17:11:25 -08:00
|
|
|
|
2012-11-01 11:30:23 -07:00
|
|
|
public function getWaitBeforeRetry(PhabricatorWorkerTask $task) {
|
2014-02-01 14:35:42 -08:00
|
|
|
return ($task->getFailureCount() * 15);
|
2012-02-27 17:11:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function doWork() {
|
2012-11-01 16:38:47 -07:00
|
|
|
$message = $this->loadMessage();
|
2014-02-01 14:35:42 -08:00
|
|
|
if (!$message) {
|
|
|
|
throw new PhabricatorWorkerPermanentFailureException(
|
|
|
|
pht('Unable to load message!'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($message->getStatus() != PhabricatorMetaMTAMail::STATUS_QUEUE) {
|
2012-02-27 17:11:25 -08:00
|
|
|
return;
|
|
|
|
}
|
2014-02-01 14:35:42 -08:00
|
|
|
|
2012-02-27 17:11:25 -08:00
|
|
|
$id = $message->getID();
|
|
|
|
$message->sendNow();
|
2014-02-01 14:35:42 -08:00
|
|
|
|
2012-02-27 17:11:25 -08:00
|
|
|
// task failed if the message is still queued
|
|
|
|
// (instead of sent, void, or failed)
|
|
|
|
if ($message->getStatus() == PhabricatorMetaMTAMail::STATUS_QUEUE) {
|
2014-02-01 14:35:42 -08:00
|
|
|
throw new Exception(
|
|
|
|
pht('Failed to send message.'));
|
2012-02-27 17:11:25 -08:00
|
|
|
}
|
|
|
|
}
|
2012-11-01 16:38:47 -07:00
|
|
|
|
|
|
|
private function loadMessage() {
|
2014-02-01 14:35:42 -08:00
|
|
|
$message_id = $this->getTaskData();
|
|
|
|
return id(new PhabricatorMetaMTAMail())->load($message_id);
|
2012-11-01 16:38:47 -07:00
|
|
|
}
|
|
|
|
|
2013-12-20 18:02:32 -08:00
|
|
|
public function renderForDisplay(PhabricatorUser $viewer) {
|
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
|
|
|
}
|