forked from zstackio/zstack
-
Notifications
You must be signed in to change notification settings - Fork 0
<feature>[longjob]: Introduce long job state and progerss notification #3293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
header/src/main/java/org/zstack/header/core/progress/ProgressUpdateExtensionPoint.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package org.zstack.header.core.progress; | ||
|
|
||
| /** | ||
| * Extension point invoked after a task progress record is persisted. | ||
| * Used to trigger downstream notifications (e.g. Long Job progress to SNS) without coupling to progress storage. | ||
| */ | ||
| public interface ProgressUpdateExtensionPoint { | ||
| void afterProgressPersisted(TaskProgressVO vo); | ||
| } |
105 changes: 105 additions & 0 deletions
105
header/src/main/java/org/zstack/header/longjob/LongJobProgressNotificationMessage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| package org.zstack.header.longjob; | ||
|
|
||
| import org.zstack.header.core.progress.TaskProgressInventory; | ||
| import org.zstack.header.core.progress.TaskProgressVO; | ||
|
|
||
| import java.io.Serializable; | ||
|
|
||
| /** | ||
| * Notification message for Long Job state change and progress update. | ||
| * Reuses LongJobInventory and TaskProgressInventory for UI consistency. | ||
| * | ||
| * <p>Webhook/BFF contract: the payload should include a 0-100 progress number. | ||
| * BFF uses {@link #getProgress()} (Integer) directly; full taskProgress is optional for future use. | ||
| */ | ||
| public class LongJobProgressNotificationMessage implements Serializable { | ||
| public enum EventType { | ||
| STATE_CHANGED, | ||
| PROGRESS_UPDATED | ||
| } | ||
|
|
||
| private LongJobInventory longJob; | ||
| /** Latest progress 0-100, derived from type=Progress latest record content. For BFF webhook. */ | ||
| private Integer progress; | ||
| /** Full progress detail; optional, BFF current version only needs {@link #getProgress()}. */ | ||
| private TaskProgressInventory taskProgress; | ||
| private EventType eventType; | ||
| private Long timestamp; | ||
|
|
||
| public LongJobInventory getLongJob() { | ||
| return longJob; | ||
| } | ||
|
|
||
| public void setLongJob(LongJobInventory longJob) { | ||
| this.longJob = longJob; | ||
| } | ||
|
|
||
| /** Progress 0-100 for BFF webhook; from latest type=Progress content. */ | ||
| public Integer getProgress() { | ||
| return progress; | ||
| } | ||
|
|
||
| public void setProgress(Integer progress) { | ||
| this.progress = progress; | ||
| } | ||
|
|
||
| /** Full task progress inventory; optional for BFF. */ | ||
| public TaskProgressInventory getTaskProgress() { | ||
| return taskProgress; | ||
| } | ||
|
|
||
| public void setTaskProgress(TaskProgressInventory taskProgress) { | ||
| this.taskProgress = taskProgress; | ||
| } | ||
|
|
||
| public EventType getEventType() { | ||
| return eventType; | ||
| } | ||
|
|
||
| public void setEventType(EventType eventType) { | ||
| this.eventType = eventType; | ||
| } | ||
|
|
||
| public Long getTimestamp() { | ||
| return timestamp; | ||
| } | ||
|
|
||
| public void setTimestamp(Long timestamp) { | ||
| this.timestamp = timestamp; | ||
| } | ||
|
|
||
| public static LongJobProgressNotificationMessage stateChanged(LongJobVO vo) { | ||
| LongJobProgressNotificationMessage msg = new LongJobProgressNotificationMessage(); | ||
| msg.longJob = LongJobInventory.valueOf(vo); | ||
| msg.eventType = EventType.STATE_CHANGED; | ||
| msg.timestamp = System.currentTimeMillis(); | ||
| return msg; | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
|
|
||
| private static int parseProgressContent(String content) { | ||
| if (content == null || content.isEmpty()) { | ||
| return 0; | ||
| } | ||
| try { | ||
| int v = Integer.parseInt(content.trim()); | ||
| return Math.min(100, Math.max(0, v)); | ||
| } catch (NumberFormatException e) { | ||
| return 0; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
longjob/src/main/java/org/zstack/longjob/sns/LongJobTaskTracker.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| package org.zstack.longjob.sns; | ||
|
|
||
| import org.zstack.core.progress.TaskTracker; | ||
| import org.zstack.header.longjob.LongJobVO; | ||
|
|
||
| /** | ||
| * Task tracker for Long Job state change and progress update notifications. | ||
| * Used by LongJobProgressNotification to receive tasks and publish to SNS. | ||
| */ | ||
| public class LongJobTaskTracker extends TaskTracker { | ||
| public static final String TASK_NAME = "longjob-progress"; | ||
|
|
||
| public static final String PARAM_STATE = "state"; | ||
| public static final String PARAM_PROGRESS = "progress"; | ||
| public static final String PARAM_LONG_JOB_UUID = "longJobUuid"; | ||
| public static final String PARAM_JOB_NAME = "jobName"; | ||
|
|
||
| public enum EventType { | ||
| STATE_CHANGED, | ||
| PROGRESS_UPDATED | ||
| } | ||
|
|
||
| public LongJobTaskTracker(String resourceUuid) { | ||
| super(resourceUuid); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getResourceType() { | ||
| return LongJobVO.class.getSimpleName(); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getTaskName() { | ||
| return TASK_NAME; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 232
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 232
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 6153
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 232
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 50374
🏁 Script executed:
# 查看完整的 TaskProgressInventory 构造器实现和 content 相关方法 cat header/src/main/java/org/zstack/header/core/progress/TaskProgressInventory.javaRepository: MatheMatrix/zstack
Length of output: 2414
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 134
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 2551
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 44
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 1070
🏁 Script executed:
Repository: MatheMatrix/zstack
Length of output: 3339
应用 i18n 转换以保持任务进度内容一致
ProgressReportService.inventory()方法在设置 content 时应用了toI18nString()转换,但此处直接设置 content 未进行相同处理。这会导致 Webhook 通知中的任务进度文案与 API 返回的文案不一致。建议参考ProgressReportService.inventory()的实现,对 content 应用toI18nString()转换:同时,arguments 的处理也应与
ProgressReportService保持一致,仅在非空时设置。🤖 Prompt for AI Agents