-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathJob.php
46 lines (36 loc) · 961 Bytes
/
Job.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace wh\queue;
use Yii;
class Job
{
protected $queueObject;
protected $payload;
protected $queueName;
public function __construct($queueObject, $payload, $queueName)
{
$this->queueObject = $queueObject;
$this->payload = $payload;
$this->queueName = $queueName;
}
public function run()
{
$this->resolveAndRun(json_decode($this->payload, true));
}
public function getQueueObject()
{
return $this->queueObject;
}
protected function resolveAndRun(array $payload)
{
list($class, $method) = $this->resolveJob($payload['job']);
$instance = Yii::createObject([
'class' => $class
]);
$instance->{$method}($this, $payload['data']);
}
protected function resolveJob($job)
{
$segments = explode('@', $job);
return count($segments) > 1 ? $segments : array($segments[0], 'run');
}
}