Skip to content

<feature>[longjob]: Introduce long job state and progerss notification#3293

Open
MatheMatrix wants to merge 1 commit into5.5.6from
sync/ye.zou/long-job-notification@@2
Open

<feature>[longjob]: Introduce long job state and progerss notification#3293
MatheMatrix wants to merge 1 commit into5.5.6from
sync/ye.zou/long-job-notification@@2

Conversation

@MatheMatrix
Copy link
Owner

GlobalConfigImpact

Resolves: ZSTAC-81237

Change-Id: I7a6f6273626e766778686d756a737771636f616d

Signed-off-by: AlanJager ye.zou@zstack.io

sync from gitlab !9114

GlobalConfigImpact

Resolves: ZSTAC-81237

Change-Id: I7a6f6273626e766778686d756a737771636f616d

Signed-off-by: AlanJager <ye.zou@zstack.io>
@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2026

概览

此次变更引入了进度更新的扩展点机制,使得进度持久化后能够触发下游通知。新增接口、通知消息类和SNS任务跟踪器,支持长任务的状态变化和进度更新的实时通知,并通过全局配置控制通知行为。

变更内容

变更组 / 文件 摘要
扩展点机制
core/src/main/java/org/zstack/core/progress/ProgressReportService.java, header/src/main/java/org/zstack/header/core/progress/ProgressUpdateExtensionPoint.java
将进度持久化改为使用中央化方法并添加后置扩展钩子,允许通过PluginRegistry获取ProgressUpdateExtensionPoint实现并在持久化后触发回调。
通知消息与配置
header/src/main/java/org/zstack/header/longjob/LongJobProgressNotificationMessage.java, longjob/src/main/java/org/zstack/longjob/LongJobGlobalConfig.java
新增序列化通知消息类,封装长任务进度信息及事件类型,提供工厂方法构建状态变化和进度更新消息;新增两个全局配置用于控制通知启用状态和及时性。
SNS任务跟踪
longjob/src/main/java/org/zstack/longjob/sns/LongJobTaskTracker.java
新增TaskTracker扩展类,定义长任务的任务名称和参数常量,支持将进度事件发布至SNS系统。

时序图

sequenceDiagram
    participant CreateProgress as ProgressReportService
    participant Registry as PluginRegistry
    participant Extension as ProgressUpdateExtensionPoint<br/>Implementations
    participant SNS as LongJobTaskTracker<br/>(SNS Publisher)
    participant Database as DatabaseFacade

    CreateProgress->>Database: persistProgress(vo)
    Database-->>CreateProgress: ✓ Persisted
    CreateProgress->>Registry: getPluginList(ProgressUpdateExtensionPoint)
    Registry-->>CreateProgress: [Extension1, Extension2, ...]
    loop For Each Extension
        CreateProgress->>Extension: afterProgressPersisted(vo)
        Note over Extension: Process notification
        Extension->>SNS: publish task event
        SNS-->>Extension: ✓ Published
        Extension-->>CreateProgress: ✓ Complete
    end
    CreateProgress-->>CreateProgress: Persistence + Notification Cycle Complete
Loading

代码审查工作量估计

🎯 3 (中等复杂度) | ⏱️ ~20 分钟

庆祝诗

🐰 进度之光闪耀舞台,
扩展点连接天地海,
通知消息远方传来,
SNS任务追踪无碍,
长任务进度实时展开,
配置灵活控制精准,
系统和谐向前迈进!🚀


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error, 1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Title check ❌ Error 标题包含拼写错误'progerss'应为'progress',且标题内容与变更集相符。 修正标题拼写:将'progerss'改为'progress',确保标题为'[longjob]: Introduce long job state and progress notification'
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive 提供的描述信息过于简洁,主要包含元数据(JIRA issue、Change-Id等)而缺乏具体的变更内容说明。 增加对本次变更的具体描述,说明引入的通知机制、新增的扩展点、GlobalConfig配置项的作用等核心变更内容。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sync/ye.zou/long-job-notification@@2

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@header/src/main/java/org/zstack/header/longjob/LongJobProgressNotificationMessage.java`:
- Around line 79-92: In LongJobProgressNotificationMessage.progressUpdated, the
TaskProgressInventory content is set directly causing i18n mismatch; change it
to mirror ProgressReportService.inventory() by calling
toI18nString(progressVO.getContent()) when setting inv.setContent(...) and only
set inv.setArguments(...) when progressVO.getArguments() is non-null (and
likewise apply toI18nString to those arguments if ProgressReportService does so)
to ensure webhook notifications match API i18n formatting.
🧹 Nitpick comments (2)
longjob/src/main/java/org/zstack/longjob/LongJobGlobalConfig.java (1)

17-18: 建议补充全局配置校验,避免非法值进入运行时
新增配置缺少类型/范围校验,若被误设为非布尔或负值,可能导致通知逻辑异常。建议补充 @GlobalConfigValidation 或显式取值范围校验/默认值。

core/src/main/java/org/zstack/core/progress/ProgressReportService.java (1)

414-422: 异常日志建议补充进度上下文
当前仅有固定文案,排查失败来源困难;建议带上 apiId/taskUuid/type 等关键信息。

🔧 建议修改
-            } catch (Throwable t) {
-                logger.warn("ProgressUpdateExtensionPoint.afterProgressPersisted failed", t);
+            } catch (Throwable t) {
+                logger.warn(String.format(
+                        "ProgressUpdateExtensionPoint.afterProgressPersisted failed (apiId=%s, taskUuid=%s, type=%s)",
+                        vo.getApiId(), vo.getTaskUuid(), vo.getType()
+                ), t);
             }

Comment on lines +79 to +92
public static LongJobProgressNotificationMessage progressUpdated(LongJobVO vo, TaskProgressVO progressVO) {
LongJobProgressNotificationMessage msg = new LongJobProgressNotificationMessage();
msg.longJob = LongJobInventory.valueOf(vo);
int percent = parseProgressContent(progressVO.getContent());
msg.progress = percent;
TaskProgressInventory inv = new TaskProgressInventory(progressVO);
if (progressVO.getContent() != null) {
inv.setContent(progressVO.getContent());
}
msg.taskProgress = inv;
msg.eventType = EventType.PROGRESS_UPDATED;
msg.timestamp = System.currentTimeMillis();
return msg;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# 定位 TaskProgressInventory 类文件
fd 'TaskProgressInventory\.java' -type f

Repository: MatheMatrix/zstack

Length of output: 232


🏁 Script executed:

# 查找 ProgressReportService 相关文件
fd 'ProgressReportService\.java' -type f

Repository: MatheMatrix/zstack

Length of output: 232


🏁 Script executed:

# 同时查找是否存在其他与任务进度库存相关的处理逻辑
rg 'class TaskProgressInventory' -A 30

Repository: MatheMatrix/zstack

Length of output: 6153


🏁 Script executed:

# 查找 ProgressReportService 相关文件
fd 'ProgressReportService' -type f

Repository: MatheMatrix/zstack

Length of output: 232


🏁 Script executed:

# 搜索 ProgressReportService 及其对 TaskProgressInventory 的处理
rg 'ProgressReportService' -A 5 -B 5

Repository: MatheMatrix/zstack

Length of output: 50374


🏁 Script executed:

# 查看完整的 TaskProgressInventory 构造器实现和 content 相关方法
cat header/src/main/java/org/zstack/header/core/progress/TaskProgressInventory.java

Repository: MatheMatrix/zstack

Length of output: 2414


🏁 Script executed:

# 定位 ProgressReportService 的完整实现
find . -name "ProgressReportService.java" -path "*/core/progress/*"

Repository: MatheMatrix/zstack

Length of output: 134


🏁 Script executed:

# 查看 ProgressReportService 中关于 TaskProgressInventory 的处理
rg 'TaskProgressInventory' core/src/main/java/org/zstack/core/progress/ProgressReportService.java -A 5 -B 5

Repository: MatheMatrix/zstack

Length of output: 2551


🏁 Script executed:

# 查看 ProgressReportService 中关于 arguments 或 i18n 的处理
rg 'arguments|i18n' core/src/main/java/org/zstack/core/progress/ProgressReportService.java -A 3 -B 3

Repository: MatheMatrix/zstack

Length of output: 44


🏁 Script executed:

# 查看 toI18nString 方法的实现
rg 'toI18nString' core/src/main/java/org/zstack/core/progress/ProgressReportService.java -B 2 -A 10

Repository: MatheMatrix/zstack

Length of output: 1070


🏁 Script executed:

# 查看 LongJobProgressNotificationMessage 的用途,是否用于 Webhook
rg 'LongJobProgressNotificationMessage' header/src/main/java/org/zstack/header/longjob/ -A 5 -B 2

Repository: MatheMatrix/zstack

Length of output: 3339


应用 i18n 转换以保持任务进度内容一致

ProgressReportService.inventory() 方法在设置 content 时应用了 toI18nString() 转换,但此处直接设置 content 未进行相同处理。这会导致 Webhook 通知中的任务进度文案与 API 返回的文案不一致。建议参考 ProgressReportService.inventory() 的实现,对 content 应用 toI18nString() 转换:

inv.setContent(toI18nString(progressVO.getContent()));

同时,arguments 的处理也应与 ProgressReportService 保持一致,仅在非空时设置。

🤖 Prompt for AI Agents
In
`@header/src/main/java/org/zstack/header/longjob/LongJobProgressNotificationMessage.java`
around lines 79 - 92, In LongJobProgressNotificationMessage.progressUpdated, the
TaskProgressInventory content is set directly causing i18n mismatch; change it
to mirror ProgressReportService.inventory() by calling
toI18nString(progressVO.getContent()) when setting inv.setContent(...) and only
set inv.setArguments(...) when progressVO.getArguments() is non-null (and
likewise apply toI18nString to those arguments if ProgressReportService does so)
to ensure webhook notifications match API i18n formatting.

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.

2 participants