Skip to content

Commit

Permalink
[11.x] Add withoutDelay() to the Queueable trait (#51555)
Browse files Browse the repository at this point in the history
* [11.x] Add `withoutDelay()` to the `Queueable` trait

* Update Queueable.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
KennedyTedesco and taylorotwell authored May 24, 2024
1 parent 022ebc9 commit f6f5a95
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Illuminate/Bus/Queueable.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ public function delay($delay)
return $this;
}

/**
* Set the delay for the job to zero seconds.
*
* @return $this
*/
public function withoutDelay()
{
$this->delay = 0;

return $this;
}

/**
* Indicate that the job should be dispatched after all database transactions have committed.
*
Expand Down
43 changes: 43 additions & 0 deletions tests/Queue/QueueDelayTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Illuminate\Tests\Queue;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Queue;
use Orchestra\Testbench\TestCase;

class QueueDelayTest extends TestCase
{
public function test_queue_delay()
{
Queue::fake();

$job = new TestJob;

dispatch($job);

$this->assertEquals(60, $job->delay);
}

public function test_queue_without_delay()
{
Queue::fake();

$job = new TestJob;

dispatch($job->withoutDelay());

$this->assertEquals(0, $job->delay);
}
}

class TestJob implements ShouldQueue
{
use Queueable;

public function __construct()
{
$this->delay(60);
}
}

0 comments on commit f6f5a95

Please sign in to comment.