Skip to content

Commit

Permalink
Using dispatch instead of fire according to \Illuminate\Contracts…
Browse files Browse the repository at this point in the history
…\Events\Dispatcher (#20446)
  • Loading branch information
fr05t1k authored and taylorotwell committed Aug 6, 2017
1 parent c912bf4 commit 1eb5bb9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/FailingJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function handle($connectionName, $job, $e = null)

$job->failed($e);
} finally {
static::events()->fire(new JobFailed(
static::events()->dispatch(new JobFailed(
$connectionName, $job, $e ?: new ManuallyFailedException
));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Queue/SyncQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected function resolveJob($payload, $queue)
protected function raiseBeforeJobEvent(Job $job)
{
if ($this->container->bound('events')) {
$this->container['events']->fire(new Events\JobProcessing($this->connectionName, $job));
$this->container['events']->dispatch(new Events\JobProcessing($this->connectionName, $job));
}
}

Expand All @@ -85,7 +85,7 @@ protected function raiseBeforeJobEvent(Job $job)
protected function raiseAfterJobEvent(Job $job)
{
if ($this->container->bound('events')) {
$this->container['events']->fire(new Events\JobProcessed($this->connectionName, $job));
$this->container['events']->dispatch(new Events\JobProcessed($this->connectionName, $job));
}
}

Expand All @@ -99,7 +99,7 @@ protected function raiseAfterJobEvent(Job $job)
protected function raiseExceptionOccurredJobEvent(Job $job, $e)
{
if ($this->container->bound('events')) {
$this->container['events']->fire(new Events\JobExceptionOccurred($this->connectionName, $job, $e));
$this->container['events']->dispatch(new Events\JobExceptionOccurred($this->connectionName, $job, $e));
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/Illuminate/Queue/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ protected function failJob($connectionName, $job, $e)
*/
protected function raiseBeforeJobEvent($connectionName, $job)
{
$this->events->fire(new Events\JobProcessing(
$this->events->dispatch(new Events\JobProcessing(
$connectionName, $job
));
}
Expand All @@ -443,7 +443,7 @@ protected function raiseBeforeJobEvent($connectionName, $job)
*/
protected function raiseAfterJobEvent($connectionName, $job)
{
$this->events->fire(new Events\JobProcessed(
$this->events->dispatch(new Events\JobProcessed(
$connectionName, $job
));
}
Expand All @@ -458,7 +458,7 @@ protected function raiseAfterJobEvent($connectionName, $job)
*/
protected function raiseExceptionOccurredJobEvent($connectionName, $job, $e)
{
$this->events->fire(new Events\JobExceptionOccurred(
$this->events->dispatch(new Events\JobExceptionOccurred(
$connectionName, $job, $e
));
}
Expand All @@ -473,7 +473,7 @@ protected function raiseExceptionOccurredJobEvent($connectionName, $job, $e)
*/
protected function raiseFailedJobEvent($connectionName, $job, $e)
{
$this->events->fire(new Events\JobFailed(
$this->events->dispatch(new Events\JobFailed(
$connectionName, $job, $e
));
}
Expand Down Expand Up @@ -555,7 +555,7 @@ public function memoryExceeded($memoryLimit)
*/
public function stop($status = 0)
{
$this->events->fire(new Events\WorkerStopping);
$this->events->dispatch(new Events\WorkerStopping);

exit($status);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Queue/QueueSyncQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testFailedJobGetsHandledWhenAnExceptionIsThrown()
$container = new \Illuminate\Container\Container;
Container::setInstance($container);
$events = m::mock('Illuminate\Contracts\Events\Dispatcher');
$events->shouldReceive('fire')->times(3);
$events->shouldReceive('dispatch')->times(3);
$container->instance('events', $events);
$container->instance('Illuminate\Contracts\Events\Dispatcher', $events);
$sync->setContainer($container);
Expand Down
20 changes: 10 additions & 10 deletions tests/Queue/QueueWorkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function test_job_can_be_fired()
$worker = $this->getWorker('default', ['queue' => [$job = new WorkerFakeJob]]);
$worker->runNextJob('default', 'queue', new WorkerOptions);
$this->assertTrue($job->fired);
$this->events->shouldHaveReceived('fire')->with(Mockery::type(JobProcessing::class))->once();
$this->events->shouldHaveReceived('fire')->with(Mockery::type(JobProcessed::class))->once();
$this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobProcessing::class))->once();
$this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobProcessed::class))->once();
}

public function test_job_can_be_fired_based_on_priority()
Expand Down Expand Up @@ -98,8 +98,8 @@ public function test_job_is_released_on_exception()
$this->assertEquals(10, $job->releaseAfter);
$this->assertFalse($job->deleted);
$this->exceptionHandler->shouldHaveReceived('report')->with($e);
$this->events->shouldHaveReceived('fire')->with(Mockery::type(JobExceptionOccurred::class))->once();
$this->events->shouldNotHaveReceived('fire', [Mockery::type(JobProcessed::class)]);
$this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobExceptionOccurred::class))->once();
$this->events->shouldNotHaveReceived('dispatch', [Mockery::type(JobProcessed::class)]);
}

public function test_job_is_not_released_if_it_has_exceeded_max_attempts()
Expand All @@ -121,9 +121,9 @@ public function test_job_is_not_released_if_it_has_exceeded_max_attempts()
$this->assertTrue($job->deleted);
$this->assertEquals($e, $job->failedWith);
$this->exceptionHandler->shouldHaveReceived('report')->with($e);
$this->events->shouldHaveReceived('fire')->with(Mockery::type(JobExceptionOccurred::class))->once();
$this->events->shouldHaveReceived('fire')->with(Mockery::type(JobFailed::class))->once();
$this->events->shouldNotHaveReceived('fire', [Mockery::type(JobProcessed::class)]);
$this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobExceptionOccurred::class))->once();
$this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobFailed::class))->once();
$this->events->shouldNotHaveReceived('dispatch', [Mockery::type(JobProcessed::class)]);
}

public function test_job_is_failed_if_it_has_already_exceeded_max_attempts()
Expand All @@ -141,9 +141,9 @@ public function test_job_is_failed_if_it_has_already_exceeded_max_attempts()
$this->assertTrue($job->deleted);
$this->assertInstanceOf(MaxAttemptsExceededException::class, $job->failedWith);
$this->exceptionHandler->shouldHaveReceived('report')->with(Mockery::type(MaxAttemptsExceededException::class));
$this->events->shouldHaveReceived('fire')->with(Mockery::type(JobExceptionOccurred::class))->once();
$this->events->shouldHaveReceived('fire')->with(Mockery::type(JobFailed::class))->once();
$this->events->shouldNotHaveReceived('fire', [Mockery::type(JobProcessed::class)]);
$this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobExceptionOccurred::class))->once();
$this->events->shouldHaveReceived('dispatch')->with(Mockery::type(JobFailed::class))->once();
$this->events->shouldNotHaveReceived('dispatch', [Mockery::type(JobProcessed::class)]);
}

public function test_job_based_max_retries()
Expand Down

0 comments on commit 1eb5bb9

Please sign in to comment.