Skip to content
Merged
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
50 changes: 50 additions & 0 deletions src/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Doppar\Queue;

use Doppar\Queue\Facades\Queue;
use Doppar\Queue\Contracts\JobInterface;

abstract class Job implements JobInterface
Expand Down Expand Up @@ -145,4 +146,53 @@ public function delayFor(int $delay): self

return $this;
}

/**
* Dispatch the job to the queue.
*
* @return string Job ID
*/
public function dispatch(): string
{
return Queue::push($this);
}

/**
* Dispatch the job to the queue after a delay.
*
* @param int $delay Delay in seconds
* @return string Job ID
*/
public function dispatchAfter(int $delay): string
{
$this->delayFor($delay);

return $this->dispatch();
}

/**
* Dispatch the job to a specific queue.
*
* @param string $queue
* @return string Job ID
*/
public function dispatchOn(string $queue): string
{
$this->onQueue($queue);

return $this->dispatch();
}

/**
* Dispatch the job.
*
* @param mixed ...$args
* @return string Job ID
*/
public static function dispatchNow(...$args): string
{
$job = new static(...$args);

return $job->dispatch();
}
}