AbstractHandler::setBody()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace DelayQueue\Handler;
4
5
use DelayQueue\Container\ContainerAwareTrait;
6
use Exception;
7
8
/**
9
 * Job处理抽象类
10
 *
11
 * Class AbstractHandler
12
 * @package DelayQueue\Handler
13
 */
14
abstract class AbstractHandler implements HandlerInterface
15
{
16
    use ContainerAwareTrait;
17
18
    /**
19
     * @var string Job唯一标识
20
     */
21
    protected $id;
22
23
    /**
24
     * @var array
25
     */
26
    protected $body;
27
28
    /**
29
     * @param string $id
30
     */
31
    public function setId($id)
32
    {
33
        $this->id = $id;
34
    }
35
36
    /**
37
     * @param array $body
38
     */
39
    public function setBody(array $body)
40
    {
41
        $this->body = $body;
42
    }
43
44
    public function run()
45
    {
46
        $this->setUp();
47
48
        try {
49
            $this->perform();
50
            $this->delayQueue->finish($this->id);
51
        } catch (Exception $exception) {
52
            $this->logger->warning(sprintf('Job execution failed %s', $exception->getMessage()));
53
        }
54
55
        $this->tearDown();
56
    }
57
58
    protected function setUp() { }
59
60
    protected function tearDown() { }
61
62
    abstract protected function perform();
63
}