1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-14 10:52:41 +01:00
phorge-phorge/src/applications/metamta/PhabricatorMetaMTAWorker.php
epriestley fcf5149b36 Clean up numerous rough edges in Mail configuration
Summary:
  - Support file attachments in Mailgun, after D8831.
  - Fix `bin/mail send-test --attach ...` flag.
  - Make `bin/mail send-test` route mail through the daemons.
  - Remove the `workerTaskID` on MetaMTAMail, which is only used (needlessly) by `bin/mail resend` and creates a huge mess elsewhere.
  - Currently, when mail fails, the daemon exits with a very generic and useless message. Instead, make `sendNow()` throw when it fails, so the real reason is surfaced. This is OK now because mail is always sent via the daemons.
  - Now that Mailgun supports attachments, document it.
  - Update a bunch of mail docs.

Test Plan:
  - Sent mail.
  - Sent mail with attachments.
  - Read documentation.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Differential Revision: https://secure.phabricator.com/D8832
2014-04-21 15:45:29 -07:00

46 lines
1.1 KiB
PHP

<?php
final class PhabricatorMetaMTAWorker
extends PhabricatorWorker {
public function getMaximumRetryCount() {
return 250;
}
public function getWaitBeforeRetry(PhabricatorWorkerTask $task) {
return ($task->getFailureCount() * 15);
}
public function doWork() {
$message = $this->loadMessage();
if (!$message) {
throw new PhabricatorWorkerPermanentFailureException(
pht('Unable to load message!'));
}
if ($message->getStatus() != PhabricatorMetaMTAMail::STATUS_QUEUE) {
return;
}
try {
$message->sendNow();
} catch (PhabricatorMetaMTAPermanentFailureException $ex) {
// If the mailer fails permanently, fail this task permanently.
throw new PhabricatorWorkerPermanentFailureException($ex->getMessage());
}
}
private function loadMessage() {
$message_id = $this->getTaskData();
return id(new PhabricatorMetaMTAMail())->load($message_id);
}
public function renderForDisplay(PhabricatorUser $viewer) {
return phutil_tag(
'pre',
array(
),
'phabricator/ $ ./bin/mail show-outbound --id '.$this->getTaskData());
}
}