Skip to content

[13.x] Make PendingDispatch conditionable#60047

Merged
taylorotwell merged 4 commits into
laravel:13.xfrom
kevinb1989:make-pendingdispatch-conditionable
May 8, 2026
Merged

[13.x] Make PendingDispatch conditionable#60047
taylorotwell merged 4 commits into
laravel:13.xfrom
kevinb1989:make-pendingdispatch-conditionable

Conversation

@kevinb1989
Copy link
Copy Markdown
Contributor

@kevinb1989 kevinb1989 commented May 8, 2026

It would be nice to configure queued jobs to be dispatch with some conditions.

I am working for a cryptocurrency company, we don't want to deal with fraudulent customers. At the same time, for better conversion, certain customers don't have to submit their personal details before payment is done.

class Customer extends Model
{
    public function hasSufficientPersonalDetails(): bool
    {
        return $this->name
            && ($this->phone_number || $this->email)
            && $this->addresses->isNotEmpty();
    }
}

use App\Jobs\SendPersonalDetailsToFraudDetectionTool;

// After payment is done.
SendPersonalDetailsToFraudDetectionTool::dispatch($customer)
    ->when($customer->hasSufficientPersonalDetails(), fn ($job) => $job->withoutDelay());

// Or
SendPersonalDetailsToFraudDetectionTool::dispatch($customer)
    ->unless($customer->hasSufficientPersonalDetails(), fn ($job) => $job->delay(180));

This is important to us, the earlier our fraud tool got the data, the earlier it can assess and stop fraudulent customers.

@jackbayliss
Copy link
Copy Markdown
Contributor

jackbayliss commented May 8, 2026

Nice! I wonder if #59879 may help with this too? 😁

@taylorotwell taylorotwell merged commit c5bf38d into laravel:13.x May 8, 2026
50 of 52 checks passed
@kevinb1989
Copy link
Copy Markdown
Contributor Author

kevinb1989 commented May 8, 2026

@jackbayliss cool feature, I have no idea about that 👀.

Still, this new feature could still be valuable when the conditions are outside the job.

For example, scammers mostly target credit card, so I could do:

SendPersonalDetailsToFraudDetectionTool::dispatch($customer)
    ->when(request()->paidByCreditCard(), fn ($job) => $job->withoutDelay());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants