mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-30 09:20:58 +01:00
Move functionality of PhabricatorMetaMTADaemon to a worker task
Summary: This will allow sending mail to be done by task workers. See T750. Task ID: # Blame Rev: Test Plan: - started taskmaster daemon in test env - used "send new test message" feature in MetMTA (with send now unchecked) - confirmed receipt of 1 email - repeated 2 & 3 with send now checked Revert Plan: Tags: Reviewers: epriestley, jungejason Reviewed By: epriestley CC: aran, epriestley Maniphest Tasks: T388, T750 Differential Revision: https://secure.phabricator.com/D1723
This commit is contained in:
parent
03a108e121
commit
d8c601f21b
9 changed files with 84 additions and 50 deletions
|
@ -600,7 +600,6 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorMetaMTAAttachment' => 'applications/metamta/storage/mail',
|
'PhabricatorMetaMTAAttachment' => 'applications/metamta/storage/mail',
|
||||||
'PhabricatorMetaMTAController' => 'applications/metamta/controller/base',
|
'PhabricatorMetaMTAController' => 'applications/metamta/controller/base',
|
||||||
'PhabricatorMetaMTADAO' => 'applications/metamta/storage/base',
|
'PhabricatorMetaMTADAO' => 'applications/metamta/storage/base',
|
||||||
'PhabricatorMetaMTADaemon' => 'applications/metamta/daemon/mta',
|
|
||||||
'PhabricatorMetaMTAEmailBodyParser' => 'applications/metamta/parser',
|
'PhabricatorMetaMTAEmailBodyParser' => 'applications/metamta/parser',
|
||||||
'PhabricatorMetaMTAEmailBodyParserTestCase' => 'applications/metamta/parser/__tests__',
|
'PhabricatorMetaMTAEmailBodyParserTestCase' => 'applications/metamta/parser/__tests__',
|
||||||
'PhabricatorMetaMTAListController' => 'applications/metamta/controller/list',
|
'PhabricatorMetaMTAListController' => 'applications/metamta/controller/list',
|
||||||
|
@ -615,6 +614,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorMetaMTASendController' => 'applications/metamta/controller/send',
|
'PhabricatorMetaMTASendController' => 'applications/metamta/controller/send',
|
||||||
'PhabricatorMetaMTASendGridReceiveController' => 'applications/metamta/controller/sendgridreceive',
|
'PhabricatorMetaMTASendGridReceiveController' => 'applications/metamta/controller/sendgridreceive',
|
||||||
'PhabricatorMetaMTAViewController' => 'applications/metamta/controller/view',
|
'PhabricatorMetaMTAViewController' => 'applications/metamta/controller/view',
|
||||||
|
'PhabricatorMetaMTAWorker' => 'applications/metamta/worker',
|
||||||
'PhabricatorMySQLFileStorageEngine' => 'applications/files/engine/mysql',
|
'PhabricatorMySQLFileStorageEngine' => 'applications/files/engine/mysql',
|
||||||
'PhabricatorOAuthClientAuthorization' => 'applications/oauthserver/storage/clientauthorization',
|
'PhabricatorOAuthClientAuthorization' => 'applications/oauthserver/storage/clientauthorization',
|
||||||
'PhabricatorOAuthClientAuthorizationBaseController' => 'applications/oauthserver/controller/clientauthorization/base',
|
'PhabricatorOAuthClientAuthorizationBaseController' => 'applications/oauthserver/controller/clientauthorization/base',
|
||||||
|
@ -1368,7 +1368,6 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorMailImplementationTestAdapter' => 'PhabricatorMailImplementationAdapter',
|
'PhabricatorMailImplementationTestAdapter' => 'PhabricatorMailImplementationAdapter',
|
||||||
'PhabricatorMetaMTAController' => 'PhabricatorController',
|
'PhabricatorMetaMTAController' => 'PhabricatorController',
|
||||||
'PhabricatorMetaMTADAO' => 'PhabricatorLiskDAO',
|
'PhabricatorMetaMTADAO' => 'PhabricatorLiskDAO',
|
||||||
'PhabricatorMetaMTADaemon' => 'PhabricatorDaemon',
|
|
||||||
'PhabricatorMetaMTAEmailBodyParserTestCase' => 'PhabricatorTestCase',
|
'PhabricatorMetaMTAEmailBodyParserTestCase' => 'PhabricatorTestCase',
|
||||||
'PhabricatorMetaMTAListController' => 'PhabricatorMetaMTAController',
|
'PhabricatorMetaMTAListController' => 'PhabricatorMetaMTAController',
|
||||||
'PhabricatorMetaMTAMail' => 'PhabricatorMetaMTADAO',
|
'PhabricatorMetaMTAMail' => 'PhabricatorMetaMTADAO',
|
||||||
|
@ -1382,6 +1381,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorMetaMTASendController' => 'PhabricatorMetaMTAController',
|
'PhabricatorMetaMTASendController' => 'PhabricatorMetaMTAController',
|
||||||
'PhabricatorMetaMTASendGridReceiveController' => 'PhabricatorMetaMTAController',
|
'PhabricatorMetaMTASendGridReceiveController' => 'PhabricatorMetaMTAController',
|
||||||
'PhabricatorMetaMTAViewController' => 'PhabricatorMetaMTAController',
|
'PhabricatorMetaMTAViewController' => 'PhabricatorMetaMTAController',
|
||||||
|
'PhabricatorMetaMTAWorker' => 'PhabricatorWorker',
|
||||||
'PhabricatorMySQLFileStorageEngine' => 'PhabricatorFileStorageEngine',
|
'PhabricatorMySQLFileStorageEngine' => 'PhabricatorFileStorageEngine',
|
||||||
'PhabricatorOAuthClientAuthorization' => 'PhabricatorOAuthServerDAO',
|
'PhabricatorOAuthClientAuthorization' => 'PhabricatorOAuthServerDAO',
|
||||||
'PhabricatorOAuthClientAuthorizationBaseController' => 'PhabricatorOAuthServerController',
|
'PhabricatorOAuthClientAuthorizationBaseController' => 'PhabricatorOAuthServerController',
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011 Facebook, Inc.
|
* Copyright 2012 Facebook, Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -75,7 +75,7 @@ class PhabricatorDaemonConsoleController extends PhabricatorDaemonController {
|
||||||
'ID',
|
'ID',
|
||||||
'Class',
|
'Class',
|
||||||
'Owner',
|
'Owner',
|
||||||
'Expries',
|
'Expires',
|
||||||
'Failures',
|
'Failures',
|
||||||
'',
|
'',
|
||||||
));
|
));
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Copyright 2011 Facebook, Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class PhabricatorMetaMTADaemon extends PhabricatorDaemon {
|
|
||||||
|
|
||||||
public function run() {
|
|
||||||
echo "OK. Sending mail";
|
|
||||||
do {
|
|
||||||
$mail = id(new PhabricatorMetaMTAMail())->loadAllWhere(
|
|
||||||
'status = %s AND nextRetry <= %d LIMIT 10',
|
|
||||||
PhabricatorMetaMTAMail::STATUS_QUEUE,
|
|
||||||
time());
|
|
||||||
foreach ($mail as $message) {
|
|
||||||
$message->sendNow();
|
|
||||||
}
|
|
||||||
$this->sleep(1);
|
|
||||||
} while (true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -171,6 +171,15 @@ class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getWorkerTaskID() {
|
||||||
|
return $this->getParam('worker-task');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setWorkerTaskID($id) {
|
||||||
|
$this->setParam('worker-task', $id);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flag that this is an auto-generated bulk message and should have bulk
|
* Flag that this is an auto-generated bulk message and should have bulk
|
||||||
* headers added to it if appropriate. Broadly, this means some flavor of
|
* headers added to it if appropriate. Broadly, this means some flavor of
|
||||||
|
@ -223,6 +232,19 @@ class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function didWriteData() {
|
||||||
|
parent::didWriteData();
|
||||||
|
|
||||||
|
if (!$this->getWorkerTaskID()) {
|
||||||
|
$mailer_task = new PhabricatorWorkerTask();
|
||||||
|
$mailer_task->setTaskClass('PhabricatorMetaMTAWorker');
|
||||||
|
$mailer_task->setData($this->getID());
|
||||||
|
$mailer_task->save();
|
||||||
|
$this->setWorkerTaskID($mailer_task->getID());
|
||||||
|
$this->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function buildDefaultMailer() {
|
public function buildDefaultMailer() {
|
||||||
$class_name = PhabricatorEnv::getEnvConfig('metamta.mail-adapter');
|
$class_name = PhabricatorEnv::getEnvConfig('metamta.mail-adapter');
|
||||||
|
|
|
@ -10,6 +10,7 @@ phutil_require_module('phabricator', 'applications/metamta/storage/base');
|
||||||
phutil_require_module('phabricator', 'applications/people/storage/preferences');
|
phutil_require_module('phabricator', 'applications/people/storage/preferences');
|
||||||
phutil_require_module('phabricator', 'applications/people/storage/user');
|
phutil_require_module('phabricator', 'applications/people/storage/user');
|
||||||
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
phutil_require_module('phabricator', 'applications/phid/handle/data');
|
||||||
|
phutil_require_module('phabricator', 'infrastructure/daemon/workers/storage/task');
|
||||||
phutil_require_module('phabricator', 'infrastructure/env');
|
phutil_require_module('phabricator', 'infrastructure/env');
|
||||||
|
|
||||||
phutil_require_module('phutil', 'symbols');
|
phutil_require_module('phutil', 'symbols');
|
||||||
|
|
51
src/applications/metamta/worker/PhabricatorMetaMTAWorker.php
Normal file
51
src/applications/metamta/worker/PhabricatorMetaMTAWorker.php
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2012 Facebook, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
final class PhabricatorMetaMTAWorker
|
||||||
|
extends PhabricatorWorker {
|
||||||
|
|
||||||
|
private $message;
|
||||||
|
|
||||||
|
public function getRequiredLeaseTime() {
|
||||||
|
$message_id = $this->getTaskData();
|
||||||
|
|
||||||
|
$this->message = id(new PhabricatorMetaMTAMail())->loadOneWhere(
|
||||||
|
'id = %d', $this->getTaskData());
|
||||||
|
if (!$this->message) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$lease_duration = max($this->message->getNextRetry() - time(), 0) + 15;
|
||||||
|
return $lease_duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function doWork() {
|
||||||
|
$message = $this->message;
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,9 +7,9 @@
|
||||||
|
|
||||||
|
|
||||||
phutil_require_module('phabricator', 'applications/metamta/storage/mail');
|
phutil_require_module('phabricator', 'applications/metamta/storage/mail');
|
||||||
phutil_require_module('phabricator', 'infrastructure/daemon/base');
|
phutil_require_module('phabricator', 'infrastructure/daemon/workers/worker');
|
||||||
|
|
||||||
phutil_require_module('phutil', 'utils');
|
phutil_require_module('phutil', 'utils');
|
||||||
|
|
||||||
|
|
||||||
phutil_require_source('PhabricatorMetaMTADaemon.php');
|
phutil_require_source('PhabricatorMetaMTAWorker.php');
|
|
@ -133,18 +133,15 @@ disable outbound mail, if you don't want to send mail or don't want to configure
|
||||||
it yet. Just set **metamta.mail-adapter** to
|
it yet. Just set **metamta.mail-adapter** to
|
||||||
"PhabricatorMailImplementationTestAdapter".
|
"PhabricatorMailImplementationTestAdapter".
|
||||||
|
|
||||||
= Configuring the MetaMTA Daemon =
|
= Configuring MetaMTA to Send Mail Using a Daemon =
|
||||||
|
|
||||||
Regardless of how you are sending outbound email, you can move the handoff to
|
Regardless of how you are sending outbound email, you can move the handoff to
|
||||||
the MTA out of the main process and into a daemon. This will greatly improve
|
the MTA out of the main process and into a daemon. This will greatly improve
|
||||||
application performance if your mailer is slow, like Amazon SES. In particular,
|
application performance if your mailer is slow, like Amazon SES. In particular,
|
||||||
commenting on Differential Revisions and Maniphest Tasks sends outbound email.
|
commenting on Differential Revisions and Maniphest Tasks sends outbound email.
|
||||||
|
|
||||||
To use the MetaMTA daemon:
|
If you set **metamta.send-immediately** to ##false## in your configuration,
|
||||||
|
MetaMTA will queue mail to be send by a PhabricatorTaskmasterDaemon.
|
||||||
- set **metamta.send-immediately** to ##false## in your configuration; and
|
|
||||||
- launch a ##metamta## daemon with ##phabricator/bin/phd launch metamta##.
|
|
||||||
|
|
||||||
For more information on using daemons, see @{article:Managing Daemons with phd}.
|
For more information on using daemons, see @{article:Managing Daemons with phd}.
|
||||||
|
|
||||||
= Testing and Debugging Outbound Email =
|
= Testing and Debugging Outbound Email =
|
||||||
|
|
|
@ -65,8 +65,6 @@ You can get a list of launchable daemons with **phd list**:
|
||||||
|
|
||||||
- **libphutil test daemons** are not generally useful unless you are
|
- **libphutil test daemons** are not generally useful unless you are
|
||||||
developing daemon infrastructure or debugging a daemon problem;
|
developing daemon infrastructure or debugging a daemon problem;
|
||||||
- **PhabricatorMetaMTADaemon** sends mail in the background, see
|
|
||||||
@{article:Configuring Outbound Email} for details;
|
|
||||||
- **PhabricatorTaskmasterDaemon** runs a generic task queue; and
|
- **PhabricatorTaskmasterDaemon** runs a generic task queue; and
|
||||||
- **PhabricatorRepository** daemons track repositories, descriptions are
|
- **PhabricatorRepository** daemons track repositories, descriptions are
|
||||||
available in the @{article:Diffusion User Guide}.
|
available in the @{article:Diffusion User Guide}.
|
||||||
|
|
Loading…
Reference in a new issue