githubtrue/backend/vendor/illuminate/queue/CallQueuedHandler.php @ cb15593b
1 |
<?php
|
---|---|
2 |
|
3 |
namespace Illuminate\Queue; |
4 |
|
5 |
use Illuminate\Contracts\Queue\Job; |
6 |
use Illuminate\Contracts\Bus\Dispatcher; |
7 |
|
8 |
class CallQueuedHandler |
9 |
{
|
10 |
/**
|
11 |
* The bus dispatcher implementation.
|
12 |
*
|
13 |
* @var \Illuminate\Contracts\Bus\Dispatcher
|
14 |
*/
|
15 |
protected $dispatcher; |
16 |
|
17 |
/**
|
18 |
* Create a new handler instance.
|
19 |
*
|
20 |
* @param \Illuminate\Contracts\Bus\Dispatcher $dispatcher
|
21 |
* @return void
|
22 |
*/
|
23 |
public function __construct(Dispatcher $dispatcher) |
24 |
{
|
25 |
$this->dispatcher = $dispatcher; |
26 |
}
|
27 |
|
28 |
/**
|
29 |
* Handle the queued job.
|
30 |
*
|
31 |
* @param \Illuminate\Contracts\Queue\Job $job
|
32 |
* @param array $data
|
33 |
* @return void
|
34 |
*/
|
35 |
public function call(Job $job, array $data) |
36 |
{
|
37 |
$command = $this->setJobInstanceIfNecessary( |
38 |
$job, unserialize($data['command']) |
39 |
);
|
40 |
|
41 |
$this->dispatcher->dispatchNow($command); |
42 |
|
43 |
if (! $job->isDeletedOrReleased()) { |
44 |
$job->delete(); |
45 |
}
|
46 |
}
|
47 |
|
48 |
/**
|
49 |
* Set the job instance of the given class if necessary.
|
50 |
*
|
51 |
* @param \Illuminate\Contracts\Queue\Job $job
|
52 |
* @param mixed $instance
|
53 |
* @return mixed
|
54 |
*/
|
55 |
protected function setJobInstanceIfNecessary(Job $job, $instance) |
56 |
{
|
57 |
if (in_array('Illuminate\Queue\InteractsWithQueue', class_uses_recursive(get_class($instance)))) { |
58 |
$instance->setJob($job); |
59 |
}
|
60 |
|
61 |
return $instance; |
62 |
}
|
63 |
|
64 |
/**
|
65 |
* Call the failed method on the job instance.
|
66 |
*
|
67 |
* @param array $data
|
68 |
* @return void
|
69 |
*/
|
70 |
public function failed(array $data) |
71 |
{
|
72 |
$command = unserialize($data['command']); |
73 |
|
74 |
if (method_exists($command, 'failed')) { |
75 |
$command->failed(); |
76 |
}
|
77 |
}
|
78 |
}
|