mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 08:12:40 +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/');
|
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',
|
'PhabricatorMailImplementationPHPMailerLiteAdapter' => 'applications/metamta/adapter/phpmailerlite',
|
||||||
'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',
|
||||||
'PhabricatorMetaMTAListController' => 'applications/metamta/controller/list',
|
'PhabricatorMetaMTAListController' => 'applications/metamta/controller/list',
|
||||||
'PhabricatorMetaMTAMail' => 'applications/metamta/storage/mail',
|
'PhabricatorMetaMTAMail' => 'applications/metamta/storage/mail',
|
||||||
'PhabricatorMetaMTAMailingList' => 'applications/metamta/storage/mailinglist',
|
'PhabricatorMetaMTAMailingList' => 'applications/metamta/storage/mailinglist',
|
||||||
|
@ -390,7 +391,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorLiskDAO' => 'LiskDAO',
|
'PhabricatorLiskDAO' => 'LiskDAO',
|
||||||
'PhabricatorLoginController' => 'PhabricatorAuthController',
|
'PhabricatorLoginController' => 'PhabricatorAuthController',
|
||||||
'PhabricatorLogoutController' => 'PhabricatorAuthController',
|
'PhabricatorLogoutController' => 'PhabricatorAuthController',
|
||||||
'PhabricatorMailImplementationAmazonSESAdapter' => 'PhabricatorMailImplementationAdapter',
|
'PhabricatorMailImplementationAmazonSESAdapter' => 'PhabricatorMailImplementationPHPMailerLiteAdapter',
|
||||||
'PhabricatorMailImplementationPHPMailerLiteAdapter' => 'PhabricatorMailImplementationAdapter',
|
'PhabricatorMailImplementationPHPMailerLiteAdapter' => 'PhabricatorMailImplementationAdapter',
|
||||||
'PhabricatorMetaMTAController' => 'PhabricatorController',
|
'PhabricatorMetaMTAController' => 'PhabricatorController',
|
||||||
'PhabricatorMetaMTADAO' => 'PhabricatorLiskDAO',
|
'PhabricatorMetaMTADAO' => 'PhabricatorLiskDAO',
|
||||||
|
|
|
@ -28,7 +28,7 @@ class PhabricatorMailImplementationAmazonSESAdapter
|
||||||
$this->mailer->customMailer = $this;
|
$this->mailer->customMailer = $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function executeSend($body) {
|
public function executeSend($body) {
|
||||||
$key = PhabricatorEnv::getEnvConfig('amazon-ses.access-key');
|
$key = PhabricatorEnv::getEnvConfig('amazon-ses.access-key');
|
||||||
$secret = PhabricatorEnv::getEnvConfig('amazon-ses.secret-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('phabricator', 'infrastructure/env');
|
||||||
|
|
||||||
phutil_require_module('phutil', 'moduleutils');
|
phutil_require_module('phutil', 'moduleutils');
|
||||||
phutil_require_module('phutil', 'utils');
|
|
||||||
|
|
||||||
|
|
||||||
phutil_require_source('PhabricatorMailImplementationAmazonSESAdapter.php');
|
phutil_require_source('PhabricatorMailImplementationAmazonSESAdapter.php');
|
||||||
|
|
|
@ -34,9 +34,7 @@ class PhabricatorMetaMTASendController extends PhabricatorMetaMTAController {
|
||||||
$mail->setIsHTML($request->getInt('html'));
|
$mail->setIsHTML($request->getInt('html'));
|
||||||
$mail->save();
|
$mail->save();
|
||||||
if ($request->getInt('immediately')) {
|
if ($request->getInt('immediately')) {
|
||||||
$mail->sendNow(
|
$mail->sendNow($force_send = true);
|
||||||
$force_send = true,
|
|
||||||
new PhabricatorMailImplementationPHPMailerLiteAdapter());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return id(new AphrontRedirectResponse())
|
return id(new AphrontRedirectResponse())
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
|
|
||||||
|
|
||||||
phutil_require_module('phabricator', 'aphront/response/redirect');
|
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/controller/base');
|
||||||
phutil_require_module('phabricator', 'applications/metamta/storage/mail');
|
phutil_require_module('phabricator', 'applications/metamta/storage/mail');
|
||||||
phutil_require_module('phabricator', 'view/form/base');
|
phutil_require_module('phabricator', 'view/form/base');
|
||||||
|
|
|
@ -16,4 +16,21 @@
|
||||||
* limitations under the License.
|
* 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();
|
$ret = parent::save();
|
||||||
|
|
||||||
if ($try_send) {
|
if ($try_send) {
|
||||||
$class_name = PhabricatorEnv::getEnvConfig('metamta.mail-adapter');
|
$this->sendNow();
|
||||||
PhutilSymbolLoader::loadClass($class_name);
|
|
||||||
$mailer = newv($class_name, array());
|
|
||||||
$this->sendNow($force_send = false, $mailer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildDefaultMailer() {
|
||||||
|
$class_name = PhabricatorEnv::getEnvConfig('metamta.mail-adapter');
|
||||||
|
PhutilSymbolLoader::loadClass($class_name);
|
||||||
|
return newv($class_name, array());
|
||||||
|
}
|
||||||
|
|
||||||
public function sendNow(
|
public function sendNow(
|
||||||
$force_send = false,
|
$force_send = false,
|
||||||
PhabricatorMailImplementationAdapter $mailer) {
|
PhabricatorMailImplementationAdapter $mailer = null) {
|
||||||
|
|
||||||
|
if ($mailer === null) {
|
||||||
|
$mailer = $this->buildDefaultMailer();
|
||||||
|
}
|
||||||
|
|
||||||
if (!$force_send) {
|
if (!$force_send) {
|
||||||
if ($this->getStatus() != self::STATUS_QUEUE) {
|
if ($this->getStatus() != self::STATUS_QUEUE) {
|
||||||
|
@ -166,7 +172,7 @@ class PhabricatorMetaMTAMail extends PhabricatorMetaMTADAO {
|
||||||
|
|
||||||
$handles = id(new PhabricatorObjectHandleData($phids))
|
$handles = id(new PhabricatorObjectHandleData($phids))
|
||||||
->loadHandles();
|
->loadHandles();
|
||||||
|
|
||||||
$params = $this->parameters;
|
$params = $this->parameters;
|
||||||
$default = PhabricatorEnv::getEnvConfig('metamta.default-address');
|
$default = PhabricatorEnv::getEnvConfig('metamta.default-address');
|
||||||
if (empty($params['from'])) {
|
if (empty($params['from'])) {
|
||||||
|
|
Loading…
Reference in a new issue