Skip to content

Instantly share code, notes, and snippets.

@sandvige
Created March 4, 2016 17:08
Show Gist options
  • Save sandvige/e149d04fe3020275889d to your computer and use it in GitHub Desktop.
Save sandvige/e149d04fe3020275889d to your computer and use it in GitHub Desktop.
<?php
namespace XXX\XXX\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Bundle\SwiftmailerBundle\Command\SendEmailCommand as OriginalSendEmailCommand;
class SendEmailCommand extends OriginalSendEmailCommand
{
/**
* @see Command
*/
protected function configure()
{
parent::configure();
$this
->setName('xxx:spool:send')
->setDescription('Sends emails from the spool repeatedly')
->addOption('waiting-time', null, InputOption::VALUE_OPTIONAL, 'Time to wait between two calls', 1000)
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
while (true) {
parent::execute($input, $output);
usleep($input->getOption('waiting-time') * 1000);
}
}
}
@sandvige
Copy link
Author

sandvige commented Mar 4, 2016

This crontab ensures the infinite loop is always running. Start it if it's not, do nothing if the pid file is valid.

* * * * * /sbin/start-stop-daemon --start --make-pidfile --pidfile /opt/xxx/run/worker01_mail.pid --chuid worker --oknodo --exec /usr/bin/php -- /opt/xxx/app/console xxx:spool:send --env=cli --no-debug > /dev/null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment