Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 148 | Details | Vergleich mit vorheriger | 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 as JobContract;
6
use InvalidArgumentException;
7
use Throwable;
8
 
9
trait InteractsWithQueue
10
{
11
    /**
12
     * The underlying queue job instance.
13
     *
14
     * @var \Illuminate\Contracts\Queue\Job|null
15
     */
16
    public $job;
17
 
18
    /**
19
     * Get the number of times the job has been attempted.
20
     *
21
     * @return int
22
     */
23
    public function attempts()
24
    {
25
        return $this->job ? $this->job->attempts() : 1;
26
    }
27
 
28
    /**
29
     * Delete the job from the queue.
30
     *
31
     * @return void
32
     */
33
    public function delete()
34
    {
35
        if ($this->job) {
36
            return $this->job->delete();
37
        }
38
    }
39
 
40
    /**
41
     * Fail the job from the queue.
42
     *
150 lars 43
     * @param  \Throwable|string|null  $exception
148 lars 44
     * @return void
45
     */
46
    public function fail($exception = null)
47
    {
150 lars 48
        if (is_string($exception)) {
49
            $exception = new ManuallyFailedException($exception);
50
        }
51
 
148 lars 52
        if ($exception instanceof Throwable || is_null($exception)) {
53
            if ($this->job) {
54
                return $this->job->fail($exception);
55
            }
56
        } else {
150 lars 57
            throw new InvalidArgumentException('The fail method requires a string or an instance of Throwable.');
148 lars 58
        }
59
    }
60
 
61
    /**
62
     * Release the job back into the queue after (n) seconds.
63
     *
64
     * @param  int  $delay
65
     * @return void
66
     */
67
    public function release($delay = 0)
68
    {
69
        if ($this->job) {
70
            return $this->job->release($delay);
71
        }
72
    }
73
 
74
    /**
75
     * Set the base queue job instance.
76
     *
77
     * @param  \Illuminate\Contracts\Queue\Job  $job
78
     * @return $this
79
     */
80
    public function setJob(JobContract $job)
81
    {
82
        $this->job = $job;
83
 
84
        return $this;
85
    }
86
}