Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Add withoutDelay() to the Queueable trait #51555

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}