MongoJob::getRawBody()   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 0
1
<?php
2
3
namespace yiicod\jobqueue\jobs;
4
5
use Illuminate\Container\Container;
6
use Illuminate\Contracts\Queue\Job as JobContract;
7
use Illuminate\Queue\Jobs\Job;
8
use stdClass;
9
use yiicod\jobqueue\queues\MongoThreadQueue;
10
11
/**
12
 * MongoJob for laravel queue
13
 *
14
 * @author Virchenko Maksim <[email protected]>
15
 */
16
class MongoJob extends Job implements JobContract
17
{
18
    /**
19
     * The database queue instance.
20
     *
21
     * @var MongoThreadQueue
22
     */
23
    protected $database;
24
25
    /**
26
     * The database job payload.
27
     *
28
     * @var StdClass
29
     */
30
    protected $job;
31
32
    /**
33
     * Create a new job instance.
34
     *
35
     * @param  Container $container
36
     * @param  MongoThreadQueue $database
37
     * @param  StdClass $job
38
     * @param  string $queue
39
     */
40
    public function __construct(Container $container, MongoThreadQueue $database, $job, $queue)
41
    {
42
        $this->job = $job;
43
        $this->queue = $queue;
44
        $this->database = $database;
45
        $this->container = $container;
46
    }
47
48
    /**
49
     * Delete the job from the queue.
50
     */
51
    public function delete()
52
    {
53
        parent::delete();
54
55
        if ($this->database->deleteReserved($this->queue, (string)$this->getJobId())) {
56
            $this->deleted = true;
57
        }
58
    }
59
60
    /**
61
     * Get the number of times the job has been attempted.
62
     *
63
     * @return int
64
     */
65
    public function attempts()
66
    {
67
        return (int)$this->job->attempts;
68
    }
69
70
    /**
71
     * Check if job reserved
72
     *
73
     * @return bool
74
     */
75
    public function reserved(): bool
76
    {
77
        return (bool)$this->job->reserved;
78
    }
79
80
    /**
81
     * Get reserved at time
82
     *
83
     * @return int
84
     */
85
    public function reservedAt(): int
86
    {
87
        return (int)$this->job->reserved_at;
88
    }
89
90
    /**
91
     * Get the job identifier.
92
     *
93
     * @return string
94
     */
95
    public function getJobId(): string
96
    {
97
        return (string)$this->job->_id;
98
    }
99
100
    /**
101
     * Get the raw body string for the job.
102
     *
103
     * @return string
104
     */
105
    public function getRawBody()
106
    {
107
        return $this->job->payload;
108
    }
109
}
110