master

laravel/framework

Last updated at: 29/12/2023 09:24

SkipIfBatchCancelled.php

TLDR

The file SkipIfBatchCancelled.php is a part of the Laravel framework's Illuminate\Queue\Middleware namespace. It contains a single class SkipIfBatchCancelled with a handle method. The purpose of this class is to process a job and skip it if the job is associated with a batch that has been cancelled.

Methods

handle

This method accepts two parameters: $job and $next. It checks if the given job has a batch method and the associated batch is cancelled. If the batch is cancelled, the method returns without performing any further action. Otherwise, it calls the $next callable, which signifies the next middleware in the queue, to proceed with the processing of the job.

Classes

None

<?php

namespace Illuminate\Queue\Middleware;

class SkipIfBatchCancelled
{
    /**
     * Process the job.
     *
     * @param  mixed  $job
     * @param  callable  $next
     * @return mixed
     */
    public function handle($job, $next)
    {
        if (method_exists($job, 'batch') && $job->batch()?->cancelled()) {
            return;
        }

        $next($job);
    }
}