Skip to content

Commit

Permalink
Merge pull request #81 from tobytwigger/fix-failing-jobs
Browse files Browse the repository at this point in the history
Fix issue with jobs overlapping at scale
  • Loading branch information
tobytwigger committed Mar 3, 2023
2 parents 19545ac + 3205f79 commit f489ba1
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 237 deletions.
463 changes: 231 additions & 232 deletions composer.lock

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions database/migrations/2023_03_03_175500_make_job_id_nullable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
/**
* Run the migrations.
*
*/
public function up()
{
Schema::table(sprintf('%s_%s', config('laravel-job-status.table_prefix'), 'job_statuses'), function (Blueprint $table) {
$table->string('job_id')->nullable()->change();
});
}

/**
* Reverse the migrations.
*
*/
public function down()
{
}
};
1 change: 0 additions & 1 deletion src/Listeners/JobExceptionOccurred.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public function handle(\Illuminate\Queue\Events\JobExceptionOccurred $event)
'status' => Status::QUEUED,
'uuid' => $helper->getJob()->uuid(),
'connection_name' => $helper->getJob()->getConnectionName(),
'job_id' => $helper->getJob()->getJobId(),
'is_unprotected' => $modifier->getJobStatus()?->is_unprotected,
]);

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Listeners/Workflow/DatabaseQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ public function it_does_track_a_new_job_when_failed_and_retried_and_already_manu
$this->assertEquals('my-fake-job', $jobStatus->alias);
$this->assertEquals(\JobStatus\Enums\Status::QUEUED, $jobStatus->status);
$this->assertEquals(0, $jobStatus->percentage);
$this->assertEquals(1, $jobStatus->job_id);
$this->assertNull($jobStatus->job_id);
$this->assertEquals('database', $jobStatus->connection_name);
$this->assertNotNull($jobStatus->uuid);
$this->assertEquals(true, $jobStatus->is_unprotected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public function it_does_track_a_new_job_when_failed_and_retried_and_already_manu
$this->assertEquals(JobFakeWithoutTrackableOrBatchable::class, $jobStatusRetryNotRan->alias);
$this->assertEquals(\JobStatus\Enums\Status::QUEUED, $jobStatusRetryNotRan->status);
$this->assertEquals(0, $jobStatusRetryNotRan->percentage);
$this->assertEquals(1, $jobStatusRetryNotRan->job_id);
$this->assertNull($jobStatusRetryNotRan->job_id);
$this->assertEquals('database', $jobStatusRetryNotRan->connection_name);
$this->assertNotNull($jobStatusRetryNotRan->uuid);
$this->assertEquals(true, $jobStatusRetryNotRan->is_unprotected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public function it_does_track_a_new_job_when_failed_and_retried_and_already_manu
$this->assertEquals(JobFakeWithoutTrackable::class, $jobStatusRetryNotRan->alias);
$this->assertEquals(\JobStatus\Enums\Status::QUEUED, $jobStatusRetryNotRan->status);
$this->assertEquals(0, $jobStatusRetryNotRan->percentage);
$this->assertEquals(1, $jobStatusRetryNotRan->job_id);
$this->assertNull($jobStatusRetryNotRan->job_id);
$this->assertEquals('database', $jobStatusRetryNotRan->connection_name);
$this->assertNotNull($jobStatusRetryNotRan->uuid);
$this->assertEquals(true, $jobStatusRetryNotRan->is_unprotected);
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Listeners/Workflow/ListenerQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ public function it_does_track_a_new_job_when_failed_and_retried_and_already_manu
$this->assertEquals('my-fake-listener', $jobStatus->alias);
$this->assertEquals(\JobStatus\Enums\Status::QUEUED, $jobStatus->status);
$this->assertEquals(0, $jobStatus->percentage);
$this->assertEquals(1, $jobStatus->job_id);
$this->assertNull($jobStatus->job_id);
$this->assertEquals('database', $jobStatus->connection_name);
$this->assertNotNull($jobStatus->uuid);
$this->assertEquals(true, $jobStatus->is_unprotected);
Expand Down

0 comments on commit f489ba1

Please sign in to comment.