mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-21 22:32:41 +01:00
Very basic daemon infrastructure, plus MetaMTA daemon.
Summary: Amazon SES seems to be working well, except that it takes more than a second to send mail in-process. Kick it out of process. (Between this and the ImplementationAdapter layer, MetaMTA almost makes sense. :/) Test Plan: Ran the daemon and got a flood of unsent test email. Reviewers: CC:
This commit is contained in:
parent
b7801c44fe
commit
193dbf16b4
10 changed files with 96 additions and 15 deletions
|
@ -30,3 +30,12 @@ if (!ini_get('date.timezone')) {
|
|||
}
|
||||
|
||||
phutil_load_library(dirname(__FILE__).'/../src/');
|
||||
|
||||
function phabricator_read_config_file($config) {
|
||||
$root = dirname(dirname(__FILE__));
|
||||
$conf = include $root.'/conf/'.$config.'.conf.php';
|
||||
if ($conf === false) {
|
||||
throw new Exception("Failed to read config file '{$config}'.");
|
||||
}
|
||||
return $conf;
|
||||
}
|
||||
|
|
38
scripts/daemon/run_daemon.php
Executable file
38
scripts/daemon/run_daemon.php
Executable file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env php
|
||||
<?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.
|
||||
*/
|
||||
|
||||
$root = dirname(dirname(dirname(__FILE__)));
|
||||
require_once $root.'/scripts/__init_script__.php';
|
||||
|
||||
$env = getenv('PHABRICATOR_ENV');
|
||||
if (!$env) {
|
||||
echo "Define PHABRICATOR_ENV before running scripts.\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$conf = phabricator_read_config_file($env);
|
||||
$conf['phabricator.env'] = $env;
|
||||
|
||||
phutil_require_module('phabricator', 'infrastructure/env');
|
||||
PhabricatorEnv::setEnvConfig($conf);
|
||||
phutil_require_module('phutil', 'symbols');
|
||||
|
||||
PhutilSymbolLoader::loadClass('PhabricatorMetaMTADaemon');
|
||||
$daemon = new PhabricatorMetaMTADaemon();
|
||||
$daemon->run();
|
|
@ -196,6 +196,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorMailImplementationPHPMailerLiteAdapter' => 'applications/metamta/adapter/phpmailerlite',
|
||||
'PhabricatorMetaMTAController' => 'applications/metamta/controller/base',
|
||||
'PhabricatorMetaMTADAO' => 'applications/metamta/storage/base',
|
||||
'PhabricatorMetaMTADaemon' => 'applications/metamta/daemon/mta',
|
||||
'PhabricatorMetaMTAListController' => 'applications/metamta/controller/list',
|
||||
'PhabricatorMetaMTAMail' => 'applications/metamta/storage/mail',
|
||||
'PhabricatorMetaMTAMailingList' => 'applications/metamta/storage/mailinglist',
|
||||
|
@ -390,7 +391,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorLiskDAO' => 'LiskDAO',
|
||||
'PhabricatorLoginController' => 'PhabricatorAuthController',
|
||||
'PhabricatorLogoutController' => 'PhabricatorAuthController',
|
||||
'PhabricatorMailImplementationAmazonSESAdapter' => 'PhabricatorMailImplementationAdapter',
|
||||
'PhabricatorMailImplementationAmazonSESAdapter' => 'PhabricatorMailImplementationPHPMailerLiteAdapter',
|
||||
'PhabricatorMailImplementationPHPMailerLiteAdapter' => 'PhabricatorMailImplementationAdapter',
|
||||
'PhabricatorMetaMTAController' => 'PhabricatorController',
|
||||
'PhabricatorMetaMTADAO' => 'PhabricatorLiskDAO',
|
||||
|
|
|
@ -28,7 +28,7 @@ class PhabricatorMailImplementationAmazonSESAdapter
|
|||
$this->mailer->customMailer = $this;
|
||||
}
|
||||
|
||||
public function executeSend($body) {
|
||||
public function executeSend($body) {
|
||||
$key = PhabricatorEnv::getEnvConfig('amazon-ses.access-key');
|
||||
$secret = PhabricatorEnv::getEnvConfig('amazon-ses.secret-key');
|
||||
|
||||
|
|
|
@ -6,11 +6,10 @@
|
|||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/metamta/adapter/base');
|
||||
phutil_require_module('phabricator', 'applications/metamta/adapter/phpmailerlite');
|
||||
phutil_require_module('phabricator', 'infrastructure/env');
|
||||
|
||||
phutil_require_module('phutil', 'moduleutils');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorMailImplementationAmazonSESAdapter.php');
|
||||
|
|
|
@ -34,9 +34,7 @@ class PhabricatorMetaMTASendController extends PhabricatorMetaMTAController {
|
|||
$mail->setIsHTML($request->getInt('html'));
|
||||
$mail->save();
|
||||
if ($request->getInt('immediately')) {
|
||||
$mail->sendNow(
|
||||
$force_send = true,
|
||||
new PhabricatorMailImplementationPHPMailerLiteAdapter());
|
||||
$mail->sendNow($force_send = true);
|
||||
}
|
||||
|
||||
return id(new AphrontRedirectResponse())
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/response/redirect');
|
||||
phutil_require_module('phabricator', 'applications/metamta/adapter/phpmailerlite');
|
||||
phutil_require_module('phabricator', 'applications/metamta/controller/base');
|
||||
phutil_require_module('phabricator', 'applications/metamta/storage/mail');
|
||||
phutil_require_module('phabricator', 'view/form/base');
|
||||
|
|
|
@ -16,4 +16,21 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Placeholder so I don't forget about this, hopefully.
|
||||
class PhabricatorMetaMTADaemon {
|
||||
|
||||
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();
|
||||
echo ".";
|
||||
}
|
||||
sleep(1);
|
||||
} while (true);
|
||||
}
|
||||
|
||||
}
|
14
src/applications/metamta/daemon/mta/__init__.php
Normal file
14
src/applications/metamta/daemon/mta/__init__.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/metamta/storage/mail');
|
||||
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorMetaMTADaemon.php');
|
|
@ -122,19 +122,25 @@ class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
|
|||
$ret = parent::save();
|
||||
|
||||
if ($try_send) {
|
||||
$class_name = PhabricatorEnv::getEnvConfig('metamta.mail-adapter');
|
||||
PhutilSymbolLoader::loadClass($class_name);
|
||||
$mailer = newv($class_name, array());
|
||||
$this->sendNow($force_send = false, $mailer);
|
||||
$this->sendNow();
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
private function buildDefaultMailer() {
|
||||
$class_name = PhabricatorEnv::getEnvConfig('metamta.mail-adapter');
|
||||
PhutilSymbolLoader::loadClass($class_name);
|
||||
return newv($class_name, array());
|
||||
}
|
||||
|
||||
public function sendNow(
|
||||
$force_send = false,
|
||||
PhabricatorMailImplementationAdapter $mailer) {
|
||||
PhabricatorMailImplementationAdapter $mailer = null) {
|
||||
|
||||
if ($mailer === null) {
|
||||
$mailer = $this->buildDefaultMailer();
|
||||
}
|
||||
|
||||
if (!$force_send) {
|
||||
if ($this->getStatus() != self::STATUS_QUEUE) {
|
||||
|
@ -166,7 +172,7 @@ class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
|
|||
|
||||
$handles = id(new PhabricatorObjectHandleData($phids))
|
||||
->loadHandles();
|
||||
|
||||
|
||||
$params = $this->parameters;
|
||||
$default = PhabricatorEnv::getEnvConfig('metamta.default-address');
|
||||
if (empty($params['from'])) {
|
||||
|
|
Loading…
Reference in a new issue