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;
4
 
5
use Illuminate\Contracts\Queue\Job;
6
use Illuminate\Contracts\Queue\Queue as QueueContract;
7
use Illuminate\Queue\Events\JobExceptionOccurred;
8
use Illuminate\Queue\Events\JobProcessed;
9
use Illuminate\Queue\Events\JobProcessing;
10
use Illuminate\Queue\Jobs\SyncJob;
11
use Throwable;
12
 
13
class SyncQueue extends Queue implements QueueContract
14
{
15
    /**
16
     * Get the size of the queue.
17
     *
18
     * @param  string|null  $queue
19
     * @return int
20
     */
21
    public function size($queue = null)
22
    {
23
        return 0;
24
    }
25
 
26
    /**
27
     * Push a new job onto the queue.
28
     *
29
     * @param  string  $job
30
     * @param  mixed  $data
31
     * @param  string|null  $queue
32
     * @return mixed
33
     *
34
     * @throws \Throwable
35
     */
36
    public function push($job, $data = '', $queue = null)
37
    {
38
        $queueJob = $this->resolveJob($this->createPayload($job, $queue, $data), $queue);
39
 
40
        try {
41
            $this->raiseBeforeJobEvent($queueJob);
42
 
43
            $queueJob->fire();
44
 
45
            $this->raiseAfterJobEvent($queueJob);
46
        } catch (Throwable $e) {
47
            $this->handleException($queueJob, $e);
48
        }
49
 
50
        return 0;
51
    }
52
 
53
    /**
54
     * Resolve a Sync job instance.
55
     *
56
     * @param  string  $payload
57
     * @param  string  $queue
58
     * @return \Illuminate\Queue\Jobs\SyncJob
59
     */
60
    protected function resolveJob($payload, $queue)
61
    {
62
        return new SyncJob($this->container, $payload, $this->connectionName, $queue);
63
    }
64
 
65
    /**
66
     * Raise the before queue job event.
67
     *
68
     * @param  \Illuminate\Contracts\Queue\Job  $job
69
     * @return void
70
     */
71
    protected function raiseBeforeJobEvent(Job $job)
72
    {
73
        if ($this->container->bound('events')) {
74
            $this->container['events']->dispatch(new JobProcessing($this->connectionName, $job));
75
        }
76
    }
77
 
78
    /**
79
     * Raise the after queue job event.
80
     *
81
     * @param  \Illuminate\Contracts\Queue\Job  $job
82
     * @return void
83
     */
84
    protected function raiseAfterJobEvent(Job $job)
85
    {
86
        if ($this->container->bound('events')) {
87
            $this->container['events']->dispatch(new JobProcessed($this->connectionName, $job));
88
        }
89
    }
90
 
91
    /**
92
     * Raise the exception occurred queue job event.
93
     *
94
     * @param  \Illuminate\Contracts\Queue\Job  $job
95
     * @param  \Throwable  $e
96
     * @return void
97
     */
98
    protected function raiseExceptionOccurredJobEvent(Job $job, Throwable $e)
99
    {
100
        if ($this->container->bound('events')) {
101
            $this->container['events']->dispatch(new JobExceptionOccurred($this->connectionName, $job, $e));
102
        }
103
    }
104
 
105
    /**
106
     * Handle an exception that occurred while processing a job.
107
     *
108
     * @param  \Illuminate\Contracts\Queue\Job  $queueJob
109
     * @param  \Throwable  $e
110
     * @return void
111
     *
112
     * @throws \Throwable
113
     */
114
    protected function handleException(Job $queueJob, Throwable $e)
115
    {
116
        $this->raiseExceptionOccurredJobEvent($queueJob, $e);
117
 
118
        $queueJob->fail($e);
119
 
120
        throw $e;
121
    }
122
 
123
    /**
124
     * Push a raw payload onto the queue.
125
     *
126
     * @param  string  $payload
127
     * @param  string|null  $queue
128
     * @param  array  $options
129
     * @return mixed
130
     */
131
    public function pushRaw($payload, $queue = null, array $options = [])
132
    {
133
        //
134
    }
135
 
136
    /**
137
     * Push a new job onto the queue after (n) seconds.
138
     *
139
     * @param  \DateTimeInterface|\DateInterval|int  $delay
140
     * @param  string  $job
141
     * @param  mixed  $data
142
     * @param  string|null  $queue
143
     * @return mixed
144
     */
145
    public function later($delay, $job, $data = '', $queue = null)
146
    {
147
        return $this->push($job, $data, $queue);
148
    }
149
 
150
    /**
151
     * Pop the next job off of the queue.
152
     *
153
     * @param  string|null  $queue
154
     * @return \Illuminate\Contracts\Queue\Job|null
155
     */
156
    public function pop($queue = null)
157
    {
158
        //
159
    }
160
}