Skip to content

Commit 01df918

Browse files
authored
[Bug] Removed WithoutOverlapping middleware and refactored to use SkipIfBatchCancelled (alexjustesen#2030)
1 parent 556c92c commit 01df918

File tree

6 files changed

+60
-23
lines changed

6 files changed

+60
-23
lines changed

app/Jobs/CheckForInternetConnectionJob.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Bus\Batchable;
1111
use Illuminate\Contracts\Queue\ShouldQueue;
1212
use Illuminate\Foundation\Queue\Queueable;
13+
use Illuminate\Queue\Middleware\SkipIfBatchCancelled;
1314

1415
class CheckForInternetConnectionJob implements ShouldQueue
1516
{
@@ -22,15 +23,21 @@ public function __construct(
2223
public Result $result,
2324
) {}
2425

26+
/**
27+
* Get the middleware the job should pass through.
28+
*/
29+
public function middleware(): array
30+
{
31+
return [
32+
new SkipIfBatchCancelled,
33+
];
34+
}
35+
2536
/**
2637
* Execute the job.
2738
*/
2839
public function handle(): void
2940
{
30-
if ($this->batch()->cancelled()) {
31-
return;
32-
}
33-
3441
$this->result->update([
3542
'status' => ResultStatus::Checking,
3643
]);

app/Jobs/Ookla/BenchmarkSpeedtestJob.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Bus\Batchable;
1111
use Illuminate\Contracts\Queue\ShouldQueue;
1212
use Illuminate\Foundation\Queue\Queueable;
13+
use Illuminate\Queue\Middleware\SkipIfBatchCancelled;
1314
use Illuminate\Support\Arr;
1415

1516
class BenchmarkSpeedtestJob implements ShouldQueue
@@ -25,14 +26,24 @@ public function __construct(
2526
public Result $result,
2627
) {}
2728

29+
/**
30+
* Get the middleware the job should pass through.
31+
*/
32+
public function middleware(): array
33+
{
34+
return [
35+
new SkipIfBatchCancelled,
36+
];
37+
}
38+
2839
/**
2940
* Execute the job.
3041
*/
3142
public function handle(): void
3243
{
3344
$settings = app(ThresholdSettings::class);
3445

35-
if ($this->batch()->cancelled() || $settings->absolute_enabled == false) {
46+
if ($settings->absolute_enabled == false) {
3647
return;
3748
}
3849

app/Jobs/Ookla/CompleteSpeedtestJob.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Bus\Batchable;
99
use Illuminate\Contracts\Queue\ShouldQueue;
1010
use Illuminate\Foundation\Queue\Queueable;
11+
use Illuminate\Queue\Middleware\SkipIfBatchCancelled;
1112

1213
class CompleteSpeedtestJob implements ShouldQueue
1314
{
@@ -20,15 +21,21 @@ public function __construct(
2021
public Result $result,
2122
) {}
2223

24+
/**
25+
* Get the middleware the job should pass through.
26+
*/
27+
public function middleware(): array
28+
{
29+
return [
30+
new SkipIfBatchCancelled,
31+
];
32+
}
33+
2334
/**
2435
* Execute the job.
2536
*/
2637
public function handle(): void
2738
{
28-
if ($this->batch()->cancelled()) {
29-
return;
30-
}
31-
3239
$this->result->update([
3340
'status' => ResultStatus::Completed,
3441
]);

app/Jobs/Ookla/RunSpeedtestJob.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Illuminate\Bus\Batchable;
1111
use Illuminate\Contracts\Queue\ShouldQueue;
1212
use Illuminate\Foundation\Queue\Queueable;
13-
use Illuminate\Queue\Middleware\WithoutOverlapping;
13+
use Illuminate\Queue\Middleware\SkipIfBatchCancelled;
1414
use Illuminate\Support\Arr;
1515
use Symfony\Component\Process\Exception\ProcessFailedException;
1616
use Symfony\Component\Process\Process;
@@ -40,18 +40,16 @@ public function __construct(
4040
*/
4141
public function middleware(): array
4242
{
43-
return [new WithoutOverlapping('run-speedtest')];
43+
return [
44+
new SkipIfBatchCancelled,
45+
];
4446
}
4547

4648
/**
4749
* Execute the job.
4850
*/
4951
public function handle(): void
5052
{
51-
if ($this->batch()->cancelled()) {
52-
return;
53-
}
54-
5553
$this->result->update([
5654
'status' => ResultStatus::Running,
5755
]);

app/Jobs/Ookla/SelectSpeedtestServerJob.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Bus\Batchable;
77
use Illuminate\Contracts\Queue\ShouldQueue;
88
use Illuminate\Foundation\Queue\Queueable;
9+
use Illuminate\Queue\Middleware\SkipIfBatchCancelled;
910
use Illuminate\Support\Arr;
1011
use Illuminate\Support\Facades\Log;
1112
use Symfony\Component\Process\Exception\ProcessFailedException;
@@ -22,15 +23,21 @@ public function __construct(
2223
public Result $result,
2324
) {}
2425

26+
/**
27+
* Get the middleware the job should pass through.
28+
*/
29+
public function middleware(): array
30+
{
31+
return [
32+
new SkipIfBatchCancelled,
33+
];
34+
}
35+
2536
/**
2637
* Execute the job.
2738
*/
2839
public function handle(): void
2940
{
30-
if ($this->batch()->cancelled()) {
31-
return;
32-
}
33-
3441
// If the server id is already set, we don't need to do anything.
3542
if (Arr::get($this->result->data, 'server.id')) {
3643
return;

app/Jobs/Ookla/SkipSpeedtestJob.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Illuminate\Bus\Batchable;
1111
use Illuminate\Contracts\Queue\ShouldQueue;
1212
use Illuminate\Foundation\Queue\Queueable;
13+
use Illuminate\Queue\Middleware\SkipIfBatchCancelled;
1314

1415
class SkipSpeedtestJob implements ShouldQueue
1516
{
@@ -22,15 +23,21 @@ public function __construct(
2223
public Result $result,
2324
) {}
2425

26+
/**
27+
* Get the middleware the job should pass through.
28+
*/
29+
public function middleware(): array
30+
{
31+
return [
32+
new SkipIfBatchCancelled,
33+
];
34+
}
35+
2536
/**
2637
* Execute the job.
2738
*/
2839
public function handle(): void
2940
{
30-
if ($this->batch()->cancelled()) {
31-
return;
32-
}
33-
3441
/**
3542
* Only skip IPs for scheduled tests.
3643
*/

0 commit comments

Comments
 (0)