• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

umbrellio / laravel-heavy-jobs / 4493340875

pending completion
4493340875

push

github

GitHub
Added support for Laravel 10 (#10)

139 of 182 relevant lines covered (76.37%)

16.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

32.56
/src/Decorators/QueueDecorator.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Umbrellio\LaravelHeavyJobs\Decorators;
6

7
use Illuminate\Contracts\Queue\Queue;
8
use Throwable;
9
use Umbrellio\LaravelHeavyJobs\Jobs\HeavyJob;
10
use Umbrellio\LaravelHeavyJobs\Jobs\ShouldStorePayload;
11

12
final class QueueDecorator implements Queue
13
{
14
    private $queue;
15

16
    public function __construct(Queue $queue)
17
    {
18
        $this->queue = $queue;
33✔
19
    }
20

21
    public function __call($name, $arguments)
22
    {
23
        return $this->queue->{$name}(...$arguments);
12✔
24
    }
25

26
    public function size($queue = null)
27
    {
28
        return $this->queue->size();
×
29
    }
30

31
    public function push($job, $data = '', $queue = null)
32
    {
33
        try {
34
            $job = $this->prepareJob($job);
30✔
35

36
            return $this->queue->push($job, $data, $queue);
30✔
37
        } catch (Throwable $throwable) {
15✔
38
            $this->markJobs([$job]);
15✔
39

40
            throw $throwable;
15✔
41
        }
42
    }
43

44
    public function pushRaw($payload, $queue = null, array $options = [])
45
    {
46
        return $this->queue->pushRaw($payload, $queue, $options);
×
47
    }
48

49
    public function pushOn($queue, $job, $data = '')
50
    {
51
        try {
52
            $job = $this->prepareJob($job);
×
53

54
            return $this->queue->pushOn($queue, $job, $data);
×
55
        } catch (Throwable $throwable) {
×
56
            $this->markJobs([$job]);
×
57

58
            throw $throwable;
×
59
        }
60
    }
61

62
    public function later($delay, $job, $data = '', $queue = null)
63
    {
64
        try {
65
            $job = $this->prepareJob($job);
×
66

67
            return $this->queue->later($delay, $job, $data, $queue);
×
68
        } catch (Throwable $throwable) {
×
69
            $this->markJobs([$job]);
×
70

71
            throw $throwable;
×
72
        }
73
    }
74

75
    public function laterOn($queue, $delay, $job, $data = '')
76
    {
77
        try {
78
            $job = $this->prepareJob($job);
×
79

80
            return $this->queue->laterOn($queue, $delay, $job, $data);
×
81
        } catch (Throwable $throwable) {
×
82
            $this->markJobs([$job]);
×
83

84
            throw $throwable;
×
85
        }
86
    }
87

88
    public function bulk($jobs, $data = '', $queue = null)
89
    {
90
        try {
91
            $jobs = $this->prepareJobs($jobs);
×
92

93
            return $this->queue->bulk($jobs, $data, $queue);
×
94
        } catch (Throwable $throwable) {
×
95
            $this->markJobs($jobs);
×
96

97
            throw $throwable;
×
98
        }
99
    }
100

101
    public function pop($queue = null)
102
    {
103
        return $this->queue->pop($queue);
×
104
    }
105

106
    public function getConnectionName(): string
107
    {
108
        return $this->queue->getConnectionName();
×
109
    }
110

111
    public function setConnectionName($name): self
112
    {
113
        $this->queue->setConnectionName($name);
×
114

115
        return $this;
×
116
    }
117

118
    private function prepareJob($job)
119
    {
120
        if (
121
            $job instanceof ShouldStorePayload &&
30✔
122
            (!method_exists($job, 'isHeavyJobsEnabled') || $job->isHeavyJobsEnabled())
30✔
123
        ) {
124
            return new HeavyJob($job);
27✔
125
        }
126

127
        return $job;
6✔
128
    }
129

130
    private function markJobs(array $jobs): void
131
    {
132
        foreach ($jobs as $job) {
15✔
133
            if ($job instanceof HeavyJob) {
15✔
134
                $job->handlePayloadRemove();
15✔
135
            }
136
        }
137
    }
138

139
    private function prepareJobs($jobs): array
140
    {
141
        return array_map(function ($job) {
×
142
            return $this->prepareJob($job);
×
143
        }, $jobs);
×
144
    }
145
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc