-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathSampleQueue.php
More file actions
51 lines (43 loc) · 1.14 KB
/
Copy pathSampleQueue.php
File metadata and controls
51 lines (43 loc) · 1.14 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
class SampleQueue extends PHPQueue\JobQueue
{
private $jobs = array();
private $file_path = "/tmp/sample_data.ser";
public function __construct()
{
parent::__construct();
if (is_file($this->file_path)) {
$data = unserialize(file_get_contents($this->file_path));
if (is_array($data)) {
$this->jobs = $data;
}
}
}
public function __destruct()
{
@file_put_contents($this->file_path, serialize($this->jobs));
}
public function addJob($newJob = null)
{
parent::addJob($newJob);
array_unshift($this->jobs, $newJob);
return true;
}
public function getJob($jobId = null)
{
parent::getJob();
if ( empty($this->jobs) ) {
throw new Exception("No more jobs.");
}
$jobData = array_pop($this->jobs);
$nextJob = new \PHPQueue\Job();
$nextJob->data = $jobData;
$nextJob->worker = 'Sample';
return $nextJob;
}
public function getQueueSize()
{
parent::getQueueSize();
return count($this->jobs);
}
}