-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add event listener on job complete that flushes the swiftmailer spool
- Loading branch information
Dominic Luechinger
committed
Apr 7, 2017
1 parent
a69e470
commit 7fbb6e1
Showing
3 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/** | ||
* Gearman Bundle for Symfony2 | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* Feel free to edit as you please, and have fun. | ||
* | ||
* @author Dominic Luechinger <[email protected]> | ||
*/ | ||
|
||
namespace Mmoreram\GearmanBundle\EventListener; | ||
|
||
use Mmoreram\GearmanBundle\GearmanEvents; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* Sends emails for the memory spool. | ||
* | ||
* Emails are sent on the gearman.client.callback.complete event. | ||
* | ||
* @author Dominic Luechinger <[email protected]> | ||
*/ | ||
class SwiftmailerEmailSenderListener implements EventSubscriberInterface | ||
{ | ||
|
||
/** | ||
* @var ContainerInterface | ||
*/ | ||
private $container; | ||
|
||
/** | ||
* Set container | ||
* | ||
* @param ContainerInterface $container Container | ||
* | ||
* @return GearmanExecute self Object | ||
*/ | ||
public function setContainer(ContainerInterface $container) | ||
{ | ||
$this->container = $container; | ||
|
||
return $this; | ||
} | ||
|
||
public function onComplete() | ||
{ | ||
if (!$this->container->has('swiftmailer.email_sender.listener')) { | ||
return; | ||
} | ||
$this->container->get('swiftmailer.email_sender.listener')->onTerminate(); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function getSubscribedEvents() | ||
{ | ||
return array( | ||
GearmanEvents::GEARMAN_CLIENT_CALLBACK_COMPLETE => 'onComplete', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters