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 Aws\Sqs\SqsClient;
6
use Illuminate\Container\Container;
7
use Illuminate\Contracts\Queue\Job as JobContract;
8
 
9
class SqsJob extends Job implements JobContract
10
{
11
    /**
12
     * The Amazon SQS client instance.
13
     *
14
     * @var \Aws\Sqs\SqsClient
15
     */
16
    protected $sqs;
17
 
18
    /**
19
     * The Amazon SQS job instance.
20
     *
21
     * @var array
22
     */
23
    protected $job;
24
 
25
    /**
26
     * Create a new job instance.
27
     *
28
     * @param  \Illuminate\Container\Container  $container
29
     * @param  \Aws\Sqs\SqsClient  $sqs
30
     * @param  array  $job
31
     * @param  string  $connectionName
32
     * @param  string  $queue
33
     * @return void
34
     */
35
    public function __construct(Container $container, SqsClient $sqs, array $job, $connectionName, $queue)
36
    {
37
        $this->sqs = $sqs;
38
        $this->job = $job;
39
        $this->queue = $queue;
40
        $this->container = $container;
41
        $this->connectionName = $connectionName;
42
    }
43
 
44
    /**
45
     * Release the job back into the queue after (n) seconds.
46
     *
47
     * @param  int  $delay
48
     * @return void
49
     */
50
    public function release($delay = 0)
51
    {
52
        parent::release($delay);
53
 
54
        $this->sqs->changeMessageVisibility([
55
            'QueueUrl' => $this->queue,
56
            'ReceiptHandle' => $this->job['ReceiptHandle'],
57
            'VisibilityTimeout' => $delay,
58
        ]);
59
    }
60
 
61
    /**
62
     * Delete the job from the queue.
63
     *
64
     * @return void
65
     */
66
    public function delete()
67
    {
68
        parent::delete();
69
 
70
        $this->sqs->deleteMessage([
71
            'QueueUrl' => $this->queue, 'ReceiptHandle' => $this->job['ReceiptHandle'],
72
        ]);
73
    }
74
 
75
    /**
76
     * Get the number of times the job has been attempted.
77
     *
78
     * @return int
79
     */
80
    public function attempts()
81
    {
82
        return (int) $this->job['Attributes']['ApproximateReceiveCount'];
83
    }
84
 
85
    /**
86
     * Get the job identifier.
87
     *
88
     * @return string
89
     */
90
    public function getJobId()
91
    {
92
        return $this->job['MessageId'];
93
    }
94
 
95
    /**
96
     * Get the raw body string for the job.
97
     *
98
     * @return string
99
     */
100
    public function getRawBody()
101
    {
102
        return $this->job['Body'];
103
    }
104
 
105
    /**
106
     * Get the underlying SQS client instance.
107
     *
108
     * @return \Aws\Sqs\SqsClient
109
     */
110
    public function getSqs()
111
    {
112
        return $this->sqs;
113
    }
114
 
115
    /**
116
     * Get the underlying raw SQS job.
117
     *
118
     * @return array
119
     */
120
    public function getSqsJob()
121
    {
122
        return $this->job;
123
    }
124
}