symfony / swiftmailer-bundle

Symfony Swiftmailer Bundle
https://symfony.com/swiftmailer-bundle
MIT License
1.56k stars 151 forks source link

Symfony - Swiftmailer spool send an email several times #221

Closed vishalpawar-tudip closed 2 years ago

vishalpawar-tudip commented 6 years ago

Hi Team,

I have a CRON Job which sends the emails. It creates about 3000 unique emails to send daily.

I have configured it like below: */1 * * * * php bin/console swiftmailer:spool:send --message-limit=100 --time-limit=20 --env=prod >/dev/null 2>&1

And clear failure is set after five minutes.

These simultaneous calls cause the multiple sending of the same email. So today, one user will receive multiple same emails even if I have only one entry in my database.

Please, let us know of any solution.

MisatoTremor commented 6 years ago

I'd suggest to encapsulate that in a script which ensures only one instance runs at a time like this:

command='php bin/console swiftmailer:spool:send --message-limit=100 --time-limit=20 --env=prod >/dev/null 2>&1'
result=`pgrep -cf "$command"`
if [ "${result}" -eq "0" ] ; then
        $command
fi
vishalpawar-tudip commented 6 years ago

Thanks for the solution @MisatoTremor .

vishalpawar-tudip commented 6 years ago

Any other solution to above issue or any possibility why this is happening?

Any help is really appreciated!!!

nicram-cf commented 5 years ago

It would be fine if bin/console swiftmailer:spool:send won't start if other instance is executed already. Some .pid file?

JAGFx commented 4 years ago

I know the are an old post, but you can combine the cron execution with a flock. See here http://manpages.ubuntu.com/manpages/bionic/fr/man1/flock.1.html

fabpot commented 2 years ago

Closing as Swiftmailer is not maintained anymore and in any case, the spool feature of Swiftmailer was really weak. Migrating to Symfony Mailer would give a way better way to send emails async.