Skip to content

Commit

Permalink
Merge pull request #5 from alchemy-fr/feature/preserve-payloads
Browse files Browse the repository at this point in the history
Add option to prevent payload files from being deleted
  • Loading branch information
aztech-dev authored Nov 14, 2016
2 parents 32ef82b + ea4e88d commit ae83862
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
18 changes: 16 additions & 2 deletions src/WorkerBundle/Commands/DispatchingConsumerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
namespace Alchemy\WorkerBundle\Commands;

use Alchemy\Worker\MessageDispatcher;
use Alchemy\Worker\WorkerInvoker;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class DispatchingConsumerCommand extends Command
Expand All @@ -23,21 +25,29 @@ class DispatchingConsumerCommand extends Command
*/
private $messageDispatcher;

/**
* @var WorkerInvoker
*/
private $workerInvoker;

/**
* @param MessageDispatcher $messageDispatcher
* @param WorkerInvoker $workerInvoker
*/
public function __construct(MessageDispatcher $messageDispatcher)
public function __construct(MessageDispatcher $messageDispatcher, WorkerInvoker $workerInvoker)
{
parent::__construct();

$this->messageDispatcher = $messageDispatcher;
$this->workerInvoker = $workerInvoker;
}

protected function configure()
{
parent::configure();

$this->setName('workers:run-dispatcher');
$this->setName('workers:run-dispatcher')
->addOption('preserve-payload', 'p', InputOption::VALUE_NONE);
}

/**
Expand All @@ -47,6 +57,10 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if ($input->getOption('preserve-payload')) {
$this->workerInvoker->preservePayloads();
}

while (true) {
$this->messageDispatcher->run();
}
Expand Down
8 changes: 6 additions & 2 deletions src/WorkerBundle/Commands/InvokeWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Alchemy\Worker\WorkerResolver;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class InvokeWorkerCommand extends Command
Expand All @@ -40,7 +41,8 @@ protected function configure()

$this->setName('workers:run-worker')
->addArgument('type')
->addArgument('body');
->addArgument('body')
->addOption('preserve-payload', 'p', InputOption::VALUE_NONE);
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand All @@ -66,6 +68,8 @@ protected function execute(InputInterface $input, OutputInterface $output)

$worker->process($body);

unlink($input->getArgument('body'));
if (! $input->getOption('preserve-payload')) {
unlink($input->getArgument('body'));
}
}
}
1 change: 1 addition & 0 deletions src/WorkerBundle/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ services:
class: Alchemy\WorkerBundle\Commands\DispatchingConsumerCommand
arguments:
- "@alchemy_worker.message_dispatcher"
- "@alchemy_worker.worker_invoker"
tags:
- { name: console.command }

Expand Down

0 comments on commit ae83862

Please sign in to comment.