Skip to content

Laravel 13.40 can now warn you when a queued job runs too long

Queue::whenJobRunsLongerThan and Schedule::whenTaskRunsLongerThan give Laravel apps a hook for catching jobs and scheduled tasks creeping toward a timeout, something the framework never offered before.

Source: Laravel

Laravel 13.40.0, released 3 November, adds Queue::whenJobRunsLongerThan() and Schedule::whenTaskRunsLongerThan(), two hooks that fire a callback when a job or scheduled task takes longer than you expect.

Queue::whenJobRunsLongerThan(CarbonInterval::seconds(90), function ($job, $duration) {
    Log::warning("{$job->resolveName()} took {$duration}s");
});

Laravel already had whenQueryingForLongerThan, whenRequestLifecycleIsLongerThan and whenCommandLifecycleIsLongerThan, but nothing equivalent for queued jobs, according to the pull request that added it. The job hook fires across every attempt, including failed ones, which Queue::after() doesn’t cover. whenTaskRunsLongerThan does the same for the scheduler, passing the task and its runtime to your callback.

Why it matters: both hooks catch a job or scheduled task creeping toward a timeout, or a hosting platform’s runtime limit, while it’s still slow rather than after it starts failing outright. That’s a log line you can alert on instead of a queue worker quietly falling behind until jobs start timing out.

Share

Related reading

More from The Wire

All briefs