Completed
Push — master ( 59a424...016a1e )
by Charles
01:52
created

AbstractEvent::handled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace yrc\events;
4
5
abstract class AbstractEvent extends \yii\base\Event
6
{
7
    protected $queue;
8
    protected $job;
9
10
    /**
11
     * Overloaded constructor
12
     * @param array $config
13
     * @param Disque\Queue $queue
14
     * @param Disque\Queue\Job $job
15
     */
16
    public function __construct($config = [], \Disque\Queue\Queue $queue, \Disque\Queue\Job $job)
17
    {
18
        parent::__construct($config);
19
        $this->queue = $queue;
20
        $this->job = $job;
21
    }
22
23
    /**
24
     * Mark the event as handled, then tell the queue it's been handled
25
     * @return true
26
     */
27
    public function handled()
28
    {
29
        $this->handled = true;
30
        $this->queue->processed($this->job);
31
        return true;
32
    }
33
    
34
    /**
35
     * Requeue the event
36
     * @return true
37
     */
38
    public function retry()
39
    {
40
        $this->handled = true;
41
        $this->queue->failed($this->job);
42
        return true;
43
    }
44
}