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

53 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(PhabricatorUser $viewer) {
return phutil_tag(
'pre',
array(
),
'phabricator/ $ ./bin/mail show-outbound --id '.$this->getTaskData());
}
}