Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Queue\Jobs;
4
 
5
use Illuminate\Container\Container;
6
use Illuminate\Contracts\Queue\Job as JobContract;
7
use Illuminate\Queue\RedisQueue;
8
 
9
class RedisJob extends Job implements JobContract
10
{
11
    /**
12
     * The Redis queue instance.
13
     *
14
     * @var \Illuminate\Queue\RedisQueue
15
     */
16
    protected $redis;
17
 
18
    /**
19
     * The Redis raw job payload.
20
     *
21
     * @var string
22
     */
23
    protected $job;
24
 
25
    /**
26
     * The JSON decoded version of "$job".
27
     *
28
     * @var array
29
     */
30
    protected $decoded;
31
 
32
    /**
33
     * The Redis job payload inside the reserved queue.
34
     *
35
     * @var string
36
     */
37
    protected $reserved;
38
 
39
    /**
40
     * Create a new job instance.
41
     *
42
     * @param  \Illuminate\Container\Container  $container
43
     * @param  \Illuminate\Queue\RedisQueue  $redis
44
     * @param  string  $job
45
     * @param  string  $reserved
46
     * @param  string  $connectionName
47
     * @param  string  $queue
48
     * @return void
49
     */
50
    public function __construct(Container $container, RedisQueue $redis, $job, $reserved, $connectionName, $queue)
51
    {
52
        // The $job variable is the original job JSON as it existed in the ready queue while
53
        // the $reserved variable is the raw JSON in the reserved queue. The exact format
54
        // of the reserved job is required in order for us to properly delete its data.
55
        $this->job = $job;
56
        $this->redis = $redis;
57
        $this->queue = $queue;
58
        $this->reserved = $reserved;
59
        $this->container = $container;
60
        $this->connectionName = $connectionName;
61
 
62
        $this->decoded = $this->payload();
63
    }
64
 
65
    /**
66
     * Get the raw body string for the job.
67
     *
68
     * @return string
69
     */
70
    public function getRawBody()
71
    {
72
        return $this->job;
73
    }
74
 
75
    /**
76
     * Delete the job from the queue.
77
     *
78
     * @return void
79
     */
80
    public function delete()
81
    {
82
        parent::delete();
83
 
84
        $this->redis->deleteReserved($this->queue, $this);
85
    }
86
 
87
    /**
88
     * Release the job back into the queue after (n) seconds.
89
     *
90
     * @param  int  $delay
91
     * @return void
92
     */
93
    public function release($delay = 0)
94
    {
95
        parent::release($delay);
96
 
97
        $this->redis->deleteAndRelease($this->queue, $this, $delay);
98
    }
99
 
100
    /**
101
     * Get the number of times the job has been attempted.
102
     *
103
     * @return int
104
     */
105
    public function attempts()
106
    {
107
        return ($this->decoded['attempts'] ?? null) + 1;
108
    }
109
 
110
    /**
111
     * Get the job identifier.
112
     *
113
     * @return string|null
114
     */
115
    public function getJobId()
116
    {
117
        return $this->decoded['id'] ?? null;
118
    }
119
 
120
    /**
121
     * Get the underlying Redis factory implementation.
122
     *
123
     * @return \Illuminate\Queue\RedisQueue
124
     */
125
    public function getRedisQueue()
126
    {
127
        return $this->redis;
128
    }
129
 
130
    /**
131
     * Get the underlying reserved Redis job.
132
     *
133
     * @return string
134
     */
135
    public function getReservedJob()
136
    {
137
        return $this->reserved;
138
    }
139
}