The dispatch function pushes the given job onto the Laravel job queue:
dispatch(new App\Jobs\SendEmails);
    public function dispatchNextJobInChain()

    {

        if (! empty(
$this->chained)) {

            
dispatch(tap(unserialize(array_shift($this->chained)), function ($next) {

                
$next->chained $this->chained;



                
$next->onConnection($next->connection ?: $this->chainConnection);

                
$next->onQueue($next->queue ?: $this->chainQueue);



                
$next->chainConnection $this->chainConnection;

                
$next->chainQueue $this->chainQueue;

                
$next->chainCatchCallbacks $this->chainCatchCallbacks;

            }));

        }

    }
    public function resolve()

    {

        return function (...
$arguments) {

            
dispatch(new CallQueuedListener(InvokeQueuedClosure::class, 'handle', [

                
'closure' => new SerializableClosure($this->closure),

                
'arguments' => $arguments,

                
'catch' => collect($this->catchCallbacks)->map(function ($callback) {

                    return new 
SerializableClosure($callback);

                })->
all(),

            ]))->
onConnection($this->connection)->onQueue($this->queue)->delay($this->delay);

        };

    }

}
    public function testJobsCanBeChainedOnSuccessUsingHelper()

    {

        
dispatch(new JobChainingTestFirstJob)->chain([

            new 
JobChainingTestSecondJob,

        ]);
    public function testLockIsReleasedForSuccessfulJobs()

    {

        
UniqueTestJob::$handled false;

        
dispatch($job = new UniqueTestJob);



        
$this->assertTrue($job::$handled);

        
$this->assertTrue($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
        $this->expectException(Exception::class);



        try {

            
dispatch($job = new UniqueTestFailJob);

        } finally {

            
$this->assertTrue($job::$handled);

            
$this->assertTrue($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
    {

        
UniqueTestRetryJob::$handled false;



        
dispatch($job = new UniqueTestRetryJob);



        
$this->assertFalse($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
    public function testLockIsNotReleasedForJobReleases()

    {

        
UniqueTestReleasedJob::$handled false;

        
dispatch($job = new UniqueTestReleasedJob);



        
$this->assertFalse($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
    {

        
UniqueUntilStartTestJob::$handled false;



        
dispatch($job = new UniqueUntilStartTestJob);



        
$this->assertFalse($this->app->get(Cache::class)->lock($this->getLockKey($job), 10)->get());
        $job = new TestJob1;



        
dispatch($job);

        
dispatch(new TestJob2);

        
dispatch($job)->onQueue('Q2');
        $job = new TestJob1;



        
dispatch($job);

        
dispatch(new TestJob2);

        
dispatch($job)->onQueue('Q2');



        
$this->assertEquals(2Queue::size());
        dispatch($job);

        
dispatch(new TestJob2);

        
dispatch($job)->onQueue('Q2');



        
$this->assertEquals(2Queue::size());

        
$this->assertEquals(1Queue::size('Q2'));