消息

Count Worker Crashes as Job Exceptions in Laravel 13.34

发布
Count Worker Crashes as Job Exceptions in Laravel 13.34 image

The Laravel team released v13.34.0 with an opt-in way to count worker crashes toward a job's maxExceptions , a timeout signal for interruptible jobs, a duration 财产在 JobProcessed event, a --queue 选择 queue:flush , 和更多。

Count Worker Crashes Toward maxExceptions

William Julian-Vicary 贡献了一个 #[CountCrashesAsExceptions] attribute for queued jobs. A job that throws an exception counts toward $maxExceptions , but a job whose worker dies mid-run (an out-of-memory kill, a segfault, or a container being stopped) does not. A job that uses retryUntil() with a rate limiter instead of $tries can keep crashing workers until its deadline passes.

With the attribute, a crashed attempt counts as one exception:

使用 Illuminate\Queue\Attributes\CountCrashesAsExceptions ;
使用 Illuminate\Queue\Attributes\MaxExceptions ;
#[ MaxExceptions ( 3 ), CountCrashesAsExceptions ]
班级 流程播客 实现 应该排队
{
民众 功能 retryUntil () : 日期时间
{
返回 现在 () -> 添加小时 ();
}
}

A public $countCrashesAsExceptions = true; property works the same way. The worker writes a cache key when it starts an opted-in job and removes it when the attempt ends. If the key is still there on the next attempt, the previous one died, and the worker counts it against maxExceptions . The job needs a maxExceptions value, and each attempt adds two cache calls, which is why the feature is opt-in.

看 #61737 更多细节。

Interruptible Jobs Are Notified Before a Timeout

杰克·贝利斯 updated the worker so a job that implements the Interruptible contract receives SIGALRM when it hits its timeout. Before this release, the worker passed SIGTERM and similar signals to interruptible jobs , but a timeout killed the worker without calling the job first. The job can now save its progress before it is marked as failed:

使用 Illuminate\Contracts\Queue\Interruptible ;
班级 GenerateReport 实现 应该排队 , Interruptible
{
民众 功能 interrupted ( 整数 $signal) : 空白
{
如果 ($signal === SIGALRM ){
$this -> 保存进度 ();
}
}
}

The worker also dispatches the JobInterrupted event added in Laravel 13.31 , and reports any exception thrown by interrupted() without blocking the timeout.

看 #61651 更多细节。

Job Duration on JobProcessed

Jack Bayliss also added a duration property to the JobProcessed event, in milliseconds. Before, you had to listen for JobProcessing 和 JobProcessed and track the start time yourself:

使用 Illuminate\Queue\Events\JobProcessed ;
事件 :: 听 ( 功能 ( JobProcessed $event) {
日志 :: 信息 ( "{ $事件 -> 工作 -> resolveName ()} took { $事件 -> 期间 }多发性硬化症” (英文):
});

The value is a float rounded to two decimal places. It is null when the event is dispatched from somewhere other than the worker.

看 #61672 更多细节。

Flush Failed Jobs for One Queue

queue:flush deletes every failed job on every queue. Jack Bayliss added a --queue option, so after a third-party API outage you can clear the failures from the affected queue and keep the rest:

php 工匠 queue:flush --queue=sftp-sync
# Combine with --hours to keep recent failures
php 工匠 queue:flush --queue=sftp-sync --hours=48

看 #61630 更多细节。

Schema::getColumn()

Francescu Garoby 添加 Schema::getColumn() , which returns the details for one column instead of the full list from getColumns() :

$列 = 架构 :: getColumn ( “用户” , '电子邮件' (英文):
$column[ 'type_name' ]; // "varchar"
$column[ ‘可空’ ]; // 错误的

It returns an empty array when the column does not exist.

看 #61759 更多细节。

assertDatabaseCount() Accepts an Array

Jack Bayliss updated assertDatabaseCount() to accept an array of table and count pairs, so you can check several tables in one call:

$this -> assertDatabaseCount ([
Person ::班级 => 1 ,
票 ::班级 => 2 ,
电影 => 10 ,
]);

看 #61727 更多细节。

Enums in Environment Checks

Dennis Petersmann 更新 App::environment() and the scheduler's environments() method to accept enums. Passing an enum to App::environment() threw an error, and passing one to environments() on a scheduled task caused the task to never run:

枚举 环境 : 细绳
{
案件 Staging = “舞台” ;
案件 生产 = '生产' ;
}
应用程序 :: 环境 ( 环境 :: 生产 (英文):
日程 :: 命令 ( 'reports:send' )
-> 日常的 ()
-> 环境 ( 环境 :: 生产 (英文):

这 @env Blade directive compiles to App::environment() , so it accepts enums too. In a separate PR, Jack Bayliss updated Queue::isPaused() to accept enums, matching Queue::pause() 和 Queue::resume() ( #61725 )。

看 #61730 更多细节。

requireMorphMap() Applies on Read

Pauline Vos extended Relation::requireMorphMap() to the read side of polymorphic relations. With it turned on, Laravel already threw a ClassMorphViolationException when saving a model with no morph map entry. When loading a morphTo relation, an unmapped *_type value was still used as a class name. Laravel now throws the same exception when a *_type value is not in the morph map, for both lazy and eager loading.

Applications that do not call requireMorphMap() are not affected.

看 #61711 更多细节。

发行说明

您可以在下面查看新功能和更新的完整列表以及之间的差异 13.33.0 and 13.34.0 在 GitHub 上。以下发行说明直接来自 变更日志 :

v13.34.0

保罗·雷德蒙德照片

Laravel News 特约撰稿人。全栈 Web 开发人员兼作家。

赞助

laravelcloud logo
Laravel 云

轻松创建和管理服务器,并在几秒钟内部署 Laravel 应用程序。

访问 Laravel Cloud
Laravel AI SDK and Laravel MCP Security Fixes: Update Now image

Laravel AI SDK and Laravel MCP Security Fixes: Update Now

阅读文章
Mailbox for Laravel: Preview and Test Rendered Email image

Mailbox for Laravel: Preview and Test Rendered Email

阅读文章
Elastic Bridge: Eloquent-Style Queries for Elasticsearch and OpenSearch image

Elastic Bridge: Eloquent-Style Queries for Elasticsearch and OpenSearch

阅读文章
Laravel Release Cycle: Versions, Support Policy, and Dates image

Laravel Release Cycle: Versions, Support Policy, and Dates

阅读文章
Unlearn.dev goes free for a weekend, October 10 and 11 image

Unlearn.dev goes free for a weekend, October 10 and 11

阅读文章
Tashil: Laravel Subscription Plans and Feature Usage Limits image

Tashil: Laravel Subscription Plans and Feature Usage Limits

阅读文章