-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathJob.php
More file actions
51 lines (46 loc) · 1.13 KB
/
Job.php
File metadata and controls
51 lines (46 loc) · 1.13 KB
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
47
48
49
50
51
<?php
namespace PHPQueue;
class Job
{
const OK = 'success';
const NOT_OK = 'failed';
public $worker;
public $job_id;
public $data;
public $status;
/**
* @param array $data
* @param mixed $jobId
*/
public function __construct($data=null, $jobId=null)
{
$this->job_id = $jobId;
if (!empty($data)) {
if (is_array($data)) {
$this->worker = $data['worker'];
$this->data = $data['data'];
} elseif (is_object($data)) {
$this->worker = $data->worker;
$this->data = $data->data;
} else {
try {
$data = json_decode($data, true);
$this->worker = $data['worker'];
$this->data = $data['data'];
} catch (\Exception $ex) {}
}
}
}
public function isSuccessful()
{
return ($this->status == self::OK);
}
public function onSuccessful()
{
$this->status = self::OK;
}
public function onError()
{
$this->status = self::NOT_OK;
}
}