Skip to content

Commit

Permalink
Use events, duh.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed May 31, 2016
1 parent 466ffb6 commit ace7f04
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/Illuminate/Queue/Console/WorkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Illuminate\Queue\Worker;
use Illuminate\Console\Command;
use Illuminate\Contracts\Queue\Job;
use Illuminate\Queue\Events\JobFailed;
use Illuminate\Queue\Events\JobProcessed;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

Expand Down Expand Up @@ -56,6 +58,11 @@ public function fire()
return $this->worker->sleep($this->option('sleep'));
}

// We'll listen to the processed and failed events so we can write information
// to the console as jobs are processed, which will let the developer watch
// which jobs are coming through a queue and be informed on its progress.
$this->listenForEvents();

$queue = $this->option('queue');

$delay = $this->option('delay');
Expand All @@ -67,16 +74,25 @@ public function fire()

$connection = $this->argument('connection');

$response = $this->runWorker(
$this->runWorker(
$connection, $queue, $delay, $memory, $this->option('daemon')
);
}

// If a job was fired by the worker, we'll write the output out to the console
// so that the developer can watch live while the queue runs in the console
// window, which will also of get logged if stdout is logged out to disk.
if (! is_null($response['job'])) {
$this->writeOutput($response['job'], $response['failed']);
}
/**
* Listen for the queue events in order to update the console output.
*
* @return void
*/
protected function listenForEvents()
{
$this->laravel['events']->listen(JobProcessed::class, function ($event) {
$this->writeOutput($event->job, false);
});

$this->laravel['events']->listen(JobFailed::class, function ($event) {
$this->writeOutput($event->job, true);
});
}

/**
Expand Down

0 comments on commit ace7f04

Please sign in to comment.