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 Pheanstalk\Job as PheanstalkJob;
8
use Pheanstalk\Pheanstalk;
9
 
10
class BeanstalkdJob extends Job implements JobContract
11
{
12
    /**
13
     * The Pheanstalk instance.
14
     *
15
     * @var \Pheanstalk\Pheanstalk
16
     */
17
    protected $pheanstalk;
18
 
19
    /**
20
     * The Pheanstalk job instance.
21
     *
22
     * @var \Pheanstalk\Job
23
     */
24
    protected $job;
25
 
26
    /**
27
     * Create a new job instance.
28
     *
29
     * @param  \Illuminate\Container\Container  $container
30
     * @param  \Pheanstalk\Pheanstalk  $pheanstalk
31
     * @param  \Pheanstalk\Job  $job
32
     * @param  string  $connectionName
33
     * @param  string  $queue
34
     * @return void
35
     */
36
    public function __construct(Container $container, Pheanstalk $pheanstalk, PheanstalkJob $job, $connectionName, $queue)
37
    {
38
        $this->job = $job;
39
        $this->queue = $queue;
40
        $this->container = $container;
41
        $this->pheanstalk = $pheanstalk;
42
        $this->connectionName = $connectionName;
43
    }
44
 
45
    /**
46
     * Release the job back into the queue after (n) seconds.
47
     *
48
     * @param  int  $delay
49
     * @return void
50
     */
51
    public function release($delay = 0)
52
    {
53
        parent::release($delay);
54
 
55
        $priority = Pheanstalk::DEFAULT_PRIORITY;
56
 
57
        $this->pheanstalk->release($this->job, $priority, $delay);
58
    }
59
 
60
    /**
61
     * Bury the job in the queue.
62
     *
63
     * @return void
64
     */
65
    public function bury()
66
    {
67
        parent::release();
68
 
69
        $this->pheanstalk->bury($this->job);
70
    }
71
 
72
    /**
73
     * Delete the job from the queue.
74
     *
75
     * @return void
76
     */
77
    public function delete()
78
    {
79
        parent::delete();
80
 
81
        $this->pheanstalk->delete($this->job);
82
    }
83
 
84
    /**
85
     * Get the number of times the job has been attempted.
86
     *
87
     * @return int
88
     */
89
    public function attempts()
90
    {
91
        $stats = $this->pheanstalk->statsJob($this->job);
92
 
93
        return (int) $stats->reserves;
94
    }
95
 
96
    /**
97
     * Get the job identifier.
98
     *
99
     * @return int
100
     */
101
    public function getJobId()
102
    {
103
        return $this->job->getId();
104
    }
105
 
106
    /**
107
     * Get the raw body string for the job.
108
     *
109
     * @return string
110
     */
111
    public function getRawBody()
112
    {
113
        return $this->job->getData();
114
    }
115
 
116
    /**
117
     * Get the underlying Pheanstalk instance.
118
     *
119
     * @return \Pheanstalk\Pheanstalk
120
     */
121
    public function getPheanstalk()
122
    {
123
        return $this->pheanstalk;
124
    }
125
 
126
    /**
127
     * Get the underlying Pheanstalk job.
128
     *
129
     * @return \Pheanstalk\Job
130
     */
131
    public function getPheanstalkJob()
132
    {
133
        return $this->job;
134
    }
135
}