forked from CoderKungfu/php-queue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBase.php
More file actions
75 lines (64 loc) · 1.66 KB
/
Base.php
File metadata and controls
75 lines (64 loc) · 1.66 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace PHPQueue\Backend;
abstract class Base
{
public $last_job;
public $last_job_id;
protected $open_items = array();
protected $connection;
public function __construct(){}
abstract public function connect();
public function beforeAdd($data=null){}
abstract public function add($data=null);
public function afterAdd(){}
public function beforeGet($jobId=null)
{
if (!empty($jobId)) {
$this->last_job_id = $jobId;
}
}
abstract public function get();
public function afterGet()
{
$id = $this->last_job_id;
$this->open_items[$id] = $this->last_job;
}
public function beforeClear($jobId=null)
{
if (!empty($jobId)) {
$this->last_job_id = $jobId;
}
}
abstract public function clear($jobId=null);
public function beforeRelease($jobId=null)
{
if (!empty($jobId)) {
$this->last_job_id = $jobId;
}
}
public function release($jobId=null){}
public function afterClearRelease()
{
$id = $this->last_job_id;
unset($this->open_items[$id]);
}
public function onError($ex){}
public function isJobOpen($jobId)
{
if (empty($this->open_items[$jobId])) {
throw new \PHPQueue\Exception\JobNotFoundException("Job was not previously retrieved.");
}
}
public function getConnection()
{
if (is_null($this->connection)) {
$this->connect();
}
return $this->connection;
}
public function setConnection($connection)
{
$this->connection = $connection;
return true;
}
}