Pārlūkot izejas kodu

Send worker emails via instant mailer not spooled one

Jordi Boggiano 6 gadi atpakaļ
vecāks
revīzija
cb964a4868

+ 23 - 7
app/config/config.yml

@@ -80,13 +80,29 @@ snc_redis:
 
 # Swiftmailer Configuration
 swiftmailer:
-    transport: '%mailer_transport%'
-    host:      '%mailer_host%'
-    username:  '%mailer_user%'
-    password:  '%mailer_password%'
-    encryption: '%mailer_encryption%'
-    auth_mode: '%mailer_auth_mode%'
-    spool:     { type: memory }
+    default_mailer: main
+    mailers:
+        # default main mailer for controllers and whatnot.. uses a memory spool
+        # to delay sending until end of the request
+        main:
+            transport: '%mailer_transport%'
+            host:      '%mailer_host%'
+            username:  '%mailer_user%'
+            password:  '%mailer_password%'
+            encryption: '%mailer_encryption%'
+            port: 587
+            auth_mode: '%mailer_auth_mode%'
+            spool:     { type: memory }
+        # fast mailer for background workers that does not spool but rather sends instantaneously
+        # request it to be injected by defining the argument as $instantMailer
+        instant:
+            transport: '%mailer_transport%'
+            host:      '%mailer_host%'
+            username:  '%mailer_user%'
+            password:  '%mailer_password%'
+            encryption: '%mailer_encryption%'
+            port: 587
+            auth_mode: '%mailer_auth_mode%'
 
 fos_user:
     db_driver:     orm

+ 4 - 2
src/Packagist/WebBundle/Model/PackageManager.php

@@ -25,6 +25,7 @@ class PackageManager
 {
     protected $doctrine;
     protected $mailer;
+    protected $instantMailer;
     protected $twig;
     protected $logger;
     protected $options;
@@ -34,10 +35,11 @@ class PackageManager
     protected $githubWorker;
     protected $metadataDir;
 
-    public function __construct(RegistryInterface $doctrine, \Swift_Mailer $mailer, \Twig_Environment $twig, LoggerInterface $logger, array $options, ProviderManager $providerManager, SearchClient $algoliaClient, string $algoliaIndexName, GitHubUserMigrationWorker $githubWorker, string $metadataDir)
+    public function __construct(RegistryInterface $doctrine, \Swift_Mailer $mailer, \Swift_Mailer $instantMailer, \Twig_Environment $twig, LoggerInterface $logger, array $options, ProviderManager $providerManager, SearchClient $algoliaClient, string $algoliaIndexName, GitHubUserMigrationWorker $githubWorker, string $metadataDir)
     {
         $this->doctrine = $doctrine;
         $this->mailer = $mailer;
+        $this->instantMailer = $instantMailer;
         $this->twig = $twig;
         $this->logger = $logger;
         $this->options = $options;
@@ -138,7 +140,7 @@ class PackageManager
                 ;
 
                 try {
-                    $this->mailer->send($message);
+                    $this->instantMailer->send($message);
                 } catch (\Swift_TransportException $e) {
                     $this->logger->error('['.get_class($e).'] '.$e->getMessage());
 

+ 2 - 0
src/Packagist/WebBundle/Resources/config/services.yml

@@ -6,6 +6,7 @@ services:
         bind:
             # services
             $redis: '@snc_redis.default_client'
+            #$instantMailer: '@swiftmailer.mailer.instant'
 
             # params
             $awsMetadata: '%aws_metadata%'
@@ -151,6 +152,7 @@ services:
         arguments:
             - '@doctrine'
             - '@mailer'
+            - '@swiftmailer.mailer.instant'
             - '@twig'
             - '@logger'
             - { from: '%mailer_from_email%', fromName: '%mailer_from_name%' }