mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +01:00
Remove retry/failure mechanisms from MetaMTA
Summary: Fixes T4202. We have old code in MetaMTA which implements gradual backoff and maximum retries. However, we have more general code in the task queue which does this, too. We can just use the more general stuff in the task queue; it obsoletes the specific stuff in MetaMTA, which is more complex and ran into some kind of issue in T4202. Remove `retryCount`, `nextRetry` (obsoleted by task queue retry mechanisms) and "simulated failures" (no longer in use). Generally, modern infrastructure has replaced these mechanisms with more general ones. Test Plan: - Sent mail. - Observed unsendable mail failing in reasonable ways in the queue. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T4202 Differential Revision: https://secure.phabricator.com/D8115
This commit is contained in:
parent
bb633fb42a
commit
4b0ef353e4
6 changed files with 29 additions and 65 deletions
2
resources/sql/autopatches/20140130.mail.1.retry.sql
Normal file
2
resources/sql/autopatches/20140130.mail.1.retry.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE {$NAMESPACE}_metamta.metamta_mail
|
||||||
|
DROP COLUMN retryCount;
|
2
resources/sql/autopatches/20140130.mail.2.next.sql
Normal file
2
resources/sql/autopatches/20140130.mail.2.next.sql
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
ALTER TABLE {$NAMESPACE}_metamta.metamta_mail
|
||||||
|
DROP COLUMN nextRetry;
|
|
@ -3,42 +3,39 @@
|
||||||
final class PhabricatorMetaMTAWorker
|
final class PhabricatorMetaMTAWorker
|
||||||
extends PhabricatorWorker {
|
extends PhabricatorWorker {
|
||||||
|
|
||||||
private $message;
|
public function getMaximumRetryCount() {
|
||||||
|
return 250;
|
||||||
|
}
|
||||||
|
|
||||||
public function getWaitBeforeRetry(PhabricatorWorkerTask $task) {
|
public function getWaitBeforeRetry(PhabricatorWorkerTask $task) {
|
||||||
$message = $this->loadMessage();
|
return ($task->getFailureCount() * 15);
|
||||||
if (!$message) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$wait = max($message->getNextRetry() - time(), 0) + 15;
|
|
||||||
return $wait;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function doWork() {
|
public function doWork() {
|
||||||
$message = $this->loadMessage();
|
$message = $this->loadMessage();
|
||||||
if (!$message
|
if (!$message) {
|
||||||
|| $message->getStatus() != PhabricatorMetaMTAMail::STATUS_QUEUE) {
|
throw new PhabricatorWorkerPermanentFailureException(
|
||||||
|
pht('Unable to load message!'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($message->getStatus() != PhabricatorMetaMTAMail::STATUS_QUEUE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = $message->getID();
|
$id = $message->getID();
|
||||||
$message->sendNow();
|
$message->sendNow();
|
||||||
|
|
||||||
// task failed if the message is still queued
|
// task failed if the message is still queued
|
||||||
// (instead of sent, void, or failed)
|
// (instead of sent, void, or failed)
|
||||||
if ($message->getStatus() == PhabricatorMetaMTAMail::STATUS_QUEUE) {
|
if ($message->getStatus() == PhabricatorMetaMTAMail::STATUS_QUEUE) {
|
||||||
throw new Exception('Failed to send message');
|
throw new Exception(
|
||||||
|
pht('Failed to send message.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function loadMessage() {
|
private function loadMessage() {
|
||||||
if (!$this->message) {
|
$message_id = $this->getTaskData();
|
||||||
$message_id = $this->getTaskData();
|
return id(new PhabricatorMetaMTAMail())->load($message_id);
|
||||||
$this->message = id(new PhabricatorMetaMTAMail())->load($message_id);
|
|
||||||
if (!$this->message) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function renderForDisplay(PhabricatorUser $viewer) {
|
public function renderForDisplay(PhabricatorUser $viewer) {
|
||||||
|
|
|
@ -54,9 +54,6 @@ final class PhabricatorMailManagementResendWorkflow
|
||||||
}
|
}
|
||||||
|
|
||||||
$message->setStatus(PhabricatorMetaMTAMail::STATUS_QUEUE);
|
$message->setStatus(PhabricatorMetaMTAMail::STATUS_QUEUE);
|
||||||
$message->setRetryCount(0);
|
|
||||||
$message->setNextRetry(time());
|
|
||||||
|
|
||||||
$message->save();
|
$message->save();
|
||||||
|
|
||||||
$mailer_task = PhabricatorWorker::scheduleTask(
|
$mailer_task = PhabricatorWorker::scheduleTask(
|
||||||
|
|
|
@ -50,8 +50,6 @@ final class PhabricatorMailManagementShowOutboundWorkflow
|
||||||
$info[] = pht('PROPERTIES');
|
$info[] = pht('PROPERTIES');
|
||||||
$info[] = pht('ID: %d', $message->getID());
|
$info[] = pht('ID: %d', $message->getID());
|
||||||
$info[] = pht('Status: %s', $message->getStatus());
|
$info[] = pht('Status: %s', $message->getStatus());
|
||||||
$info[] = pht('Retry Count: %s', $message->getRetryCount());
|
|
||||||
$info[] = pht('Next Retry: %s', $message->getNextRetry());
|
|
||||||
$info[] = pht('Related PHID: %s', $message->getRelatedPHID());
|
$info[] = pht('Related PHID: %s', $message->getRelatedPHID());
|
||||||
$info[] = pht('Message: %s', $message->getMessage());
|
$info[] = pht('Message: %s', $message->getMessage());
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See #394445 for an explanation of why this thing even exists.
|
|
||||||
*
|
|
||||||
* @task recipients Managing Recipients
|
* @task recipients Managing Recipients
|
||||||
*/
|
*/
|
||||||
final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
|
final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
|
||||||
|
@ -12,14 +10,11 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
|
||||||
const STATUS_FAIL = 'fail';
|
const STATUS_FAIL = 'fail';
|
||||||
const STATUS_VOID = 'void';
|
const STATUS_VOID = 'void';
|
||||||
|
|
||||||
const MAX_RETRIES = 250;
|
|
||||||
const RETRY_DELAY = 5;
|
const RETRY_DELAY = 5;
|
||||||
|
|
||||||
protected $parameters;
|
protected $parameters;
|
||||||
protected $status;
|
protected $status;
|
||||||
protected $message;
|
protected $message;
|
||||||
protected $retryCount;
|
|
||||||
protected $nextRetry;
|
|
||||||
protected $relatedPHID;
|
protected $relatedPHID;
|
||||||
|
|
||||||
private $excludePHIDs = array();
|
private $excludePHIDs = array();
|
||||||
|
@ -28,8 +23,6 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
|
|
||||||
$this->status = self::STATUS_QUEUE;
|
$this->status = self::STATUS_QUEUE;
|
||||||
$this->retryCount = 0;
|
|
||||||
$this->nextRetry = time();
|
|
||||||
$this->parameters = array();
|
$this->parameters = array();
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
@ -228,15 +221,6 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSimulatedFailureCount() {
|
|
||||||
return nonempty($this->getParam('simulated-failures'), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setSimulatedFailureCount($count) {
|
|
||||||
$this->setParam('simulated-failures', $count);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getWorkerTaskID() {
|
public function getWorkerTaskID() {
|
||||||
return $this->getParam('worker-task');
|
return $this->getParam('worker-task');
|
||||||
}
|
}
|
||||||
|
@ -339,10 +323,6 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
|
||||||
if ($this->getStatus() != self::STATUS_QUEUE) {
|
if ($this->getStatus() != self::STATUS_QUEUE) {
|
||||||
throw new Exception("Trying to send an already-sent mail!");
|
throw new Exception("Trying to send an already-sent mail!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (time() < $this->getNextRetry()) {
|
|
||||||
throw new Exception("Trying to send an email before next retry!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -611,32 +591,20 @@ final class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
|
||||||
return $this->save();
|
return $this->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->getRetryCount() < $this->getSimulatedFailureCount()) {
|
try {
|
||||||
|
$ok = $mailer->send();
|
||||||
|
$error = null;
|
||||||
|
} catch (PhabricatorMetaMTAPermanentFailureException $ex) {
|
||||||
|
$this->setStatus(self::STATUS_FAIL);
|
||||||
|
$this->setMessage($ex->getMessage());
|
||||||
|
return $this->save();
|
||||||
|
} catch (Exception $ex) {
|
||||||
$ok = false;
|
$ok = false;
|
||||||
$error = 'Simulated failure.';
|
$error = $ex->getMessage()."\n".$ex->getTraceAsString();
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
$ok = $mailer->send();
|
|
||||||
$error = null;
|
|
||||||
} catch (PhabricatorMetaMTAPermanentFailureException $ex) {
|
|
||||||
$this->setStatus(self::STATUS_FAIL);
|
|
||||||
$this->setMessage($ex->getMessage());
|
|
||||||
return $this->save();
|
|
||||||
} catch (Exception $ex) {
|
|
||||||
$ok = false;
|
|
||||||
$error = $ex->getMessage()."\n".$ex->getTraceAsString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$ok) {
|
if (!$ok) {
|
||||||
$this->setMessage($error);
|
$this->setMessage($error);
|
||||||
if ($this->getRetryCount() > self::MAX_RETRIES) {
|
|
||||||
$this->setStatus(self::STATUS_FAIL);
|
|
||||||
} else {
|
|
||||||
$this->setRetryCount($this->getRetryCount() + 1);
|
|
||||||
$next_retry = time() + ($this->getRetryCount() * self::RETRY_DELAY);
|
|
||||||
$this->setNextRetry($next_retry);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$this->setStatus(self::STATUS_SENT);
|
$this->setStatus(self::STATUS_SENT);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue