Skip to content

Commit fc4f7e7

Browse files
author
Peter Klooster
committed
Added option to disable tracking
1 parent 73010a0 commit fc4f7e7

File tree

8 files changed

+44
-6
lines changed

8 files changed

+44
-6
lines changed

src/JobStatus.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function getIsQueuedAttribute()
8787
return $this->status === self::STATUS_QUEUED;
8888
}
8989

90-
public function getIsRetrying()
90+
public function getIsRetryingAttribute()
9191
{
9292
return $this->status === self::STATUS_RETRYING;
9393
}

src/Trackable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ trait Trackable
1414
protected $statusId;
1515
protected $progressNow = 0;
1616
protected $progressMax = 0;
17+
protected $shouldTrack = true;
1718

1819
protected function setProgressMax($value)
1920
{
@@ -76,7 +77,7 @@ public function getJobStatusId()
7677

7778
public function __sleep()
7879
{
79-
if (!$this->statusId) {
80+
if (!$this->statusId && $this->shouldTrack) {
8081
$this->prepareStatus();
8182
}
8283

tests/Feature/TrackableTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Imtigger\LaravelJobStatus\Tests\Data\TestJobWithDatabase;
1111
use Imtigger\LaravelJobStatus\Tests\Data\TestJobWithException;
1212
use Imtigger\LaravelJobStatus\Tests\Data\TestJobWithoutConstruct;
13+
use Imtigger\LaravelJobStatus\Tests\Data\TestJobWithoutTracking;
1314

1415
class TrackableTest extends TestCase
1516
{
@@ -75,4 +76,17 @@ public function testWithoutPrepareStatus()
7576

7677
$this->assertEquals(1, JobStatus::query()->count());
7778
}
79+
80+
public function testWithoutPrepareStatusAndTrackingDisabled()
81+
{
82+
$job = new TestJobWithoutTracking();
83+
84+
$this->assertNull($job->getJobStatusId());
85+
86+
$this->assertEquals(0, JobStatus::query()->count());
87+
88+
app(Dispatcher::class)->dispatch($job);
89+
90+
$this->assertEquals(0, JobStatus::query()->count());
91+
}
7892
}

tests/_data/TestJob.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Illuminate\Contracts\Queue\ShouldQueue;
77
use Illuminate\Foundation\Bus\Dispatchable;
88
use Illuminate\Queue\InteractsWithQueue;
9-
use Illuminate\Queue\SerializesModels;
109
use Imtigger\LaravelJobStatus\Trackable;
1110
use Imtigger\LaravelJobStatus\TrackableJob;
1211

tests/_data/TestJobWithDatabase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
99
use Illuminate\Foundation\Testing\Constraints\HasInDatabase;
1010
use Illuminate\Queue\InteractsWithQueue;
11-
use Illuminate\Queue\SerializesModels;
1211
use Imtigger\LaravelJobStatus\Tests\Feature\TestCase;
1312
use Imtigger\LaravelJobStatus\Trackable;
1413
use Imtigger\LaravelJobStatus\TrackableJob;

tests/_data/TestJobWithException.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Illuminate\Contracts\Queue\ShouldQueue;
77
use Illuminate\Foundation\Bus\Dispatchable;
88
use Illuminate\Queue\InteractsWithQueue;
9-
use Illuminate\Queue\SerializesModels;
109
use Imtigger\LaravelJobStatus\Trackable;
1110
use Imtigger\LaravelJobStatus\TrackableJob;
1211

tests/_data/TestJobWithoutConstruct.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Illuminate\Contracts\Queue\ShouldQueue;
77
use Illuminate\Foundation\Bus\Dispatchable;
88
use Illuminate\Queue\InteractsWithQueue;
9-
use Illuminate\Queue\SerializesModels;
109
use Imtigger\LaravelJobStatus\Trackable;
1110
use Imtigger\LaravelJobStatus\TrackableJob;
1211

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Imtigger\LaravelJobStatus\Tests\Data;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Contracts\Queue\ShouldQueue;
7+
use Illuminate\Foundation\Bus\Dispatchable;
8+
use Illuminate\Queue\InteractsWithQueue;
9+
use Imtigger\LaravelJobStatus\Trackable;
10+
use Imtigger\LaravelJobStatus\TrackableJob;
11+
12+
class TestJobWithoutTracking implements ShouldQueue, TrackableJob
13+
{
14+
use InteractsWithQueue;
15+
use Queueable;
16+
use Dispatchable;
17+
use Trackable;
18+
19+
public function __construct()
20+
{
21+
$this->shouldTrack = false;
22+
}
23+
24+
public function handle()
25+
{
26+
}
27+
}

0 commit comments

Comments
 (0)