michelsalib / BCCResqueBundle

The BCC resque bundle provides integration of php-resque to Symfony2. It is inspired from resque, a Redis-backed Ruby library for creating background jobs, placing them on multiple queues, and processing them later.
122 stars 91 forks source link

Event kernel.terminate is not called hence SwiftMailer spool does not work #135

Closed ahmadrabie closed 8 years ago

ahmadrabie commented 8 years ago

Based on Symfony's SwiftMailer doc about using spool when you're using spool option (e.g. memory) emails will be sent on kernel.terminate event.

I have a job inside which I'm sending an email using swift mailer which doesn't seem to work but when I turn of spool option emails are sent.

How do I make sure that Kernel's terminate event is correctly dispatched in a Resque job? Where should I look for this? I'm new to Symfony but maybe we need $kernel->terminate() or something somewhere!

mrardon commented 8 years ago

Have you tried this? http://symfony.com/doc/current/cookbook/console/sending_emails.html#using-memory-spooling

Basically this worked when I tried it (Assuming you are using ContainerAwareJob):

        $mailer = $this->getContainer()->get('mailer');
        $spool = $mailer->getTransport()->getSpool();
        $transport = $this->getContainer()->get('swiftmailer.transport.real');
        $spool->flushQueue($transport);
srigi commented 6 years ago

I found another solution - unspooling memory spool manually by custom event: https://stackoverflow.com/questions/29802225/swiftmailer-not-sending-immediately/51730638#51730638