class BatchableJobChecksCancellationRule implements Rule

A queued job that uses the Batchable trait must respect early batch cancellation, either by checking $this->batch()?->cancelled() at the start of handle(), or by registering the SkipIfBatchCancelled middleware from middleware().

Cancelling a batch ($batch->cancel(), or the automatic cancel on first failure when the batch is not allowFailures) only stops future dispatches from running their body. Hypervel does not forcibly kill jobs already on the queue: each still wakes up and, unless it checks cancelled(), runs its full body. That is wasted work at best, and at worst it keeps mutating state (writing files, calling external APIs, charging cards) for a batch the caller has already abandoned.

Each concrete job is checked using its effective methods, including methods inherited from parents and traits. Overridden methods do not supply a guard. Unlike upstream, which accepts any method named cancelled(), a check is recognized by type: the batch's cancelled() or canceled(), the job's batching(), or the middleware class. The rule reports a missing recognized check, not proof that a canceled batch does no work.

Traits

Methods

__construct(Parser $parser, ScopeFactory $scopeFactory, NodeScopeResolver $nodeScopeResolver, ReflectionProvider $reflectionProvider)

Create a new rule instance.

string
getNodeType()

Get the node type the rule inspects.

array
processNode(Node $node, Scope $scope)

Report a batchable queued job without a recognized cancellation check.

Details

at line 77
__construct(Parser $parser, ScopeFactory $scopeFactory, NodeScopeResolver $nodeScopeResolver, ReflectionProvider $reflectionProvider)

Create a new rule instance.

Parameters

Parser $parser
ScopeFactory $scopeFactory
NodeScopeResolver $nodeScopeResolver
ReflectionProvider $reflectionProvider

at line 89
string getNodeType()

Get the node type the rule inspects.

Return Value

string

at line 101
array processNode(Node $node, Scope $scope)

Report a batchable queued job without a recognized cancellation check.

Parameters

Node $node
Scope $scope

Return Value

array