Copilot commented on code in PR #3777:
URL: https://github.com/apache/hertzbeat/pull/3777#discussion_r2379472326
##########
hertzbeat-collector/hertzbeat-collector-common/src/main/java/org/apache/hertzbeat/collector/constants/ScheduleTypeEnum.java:
##########
@@ -0,0 +1,22 @@
+package org.apache.hertzbeat.collector.constants;
Review Comment:
Missing file header with Apache license. All Java files in this project
should include the standard Apache License header.
##########
hertzbeat-collector/hertzbeat-collector-common/src/main/java/org/apache/hertzbeat/collector/timer/TimerDispatcher.java:
##########
@@ -76,6 +82,7 @@ public TimerDispatcher() {
this.started = new AtomicBoolean(true);
}
+
Review Comment:
Extra blank line should be removed to maintain consistent code formatting.
```suggestion
```
##########
web-app/src/app/routes/monitor/monitor-form/monitor-form.component.html:
##########
@@ -158,6 +158,18 @@
</nz-form-item>
<nz-form-item>
+ <nz-form-label nzSpan="7" [nzFor]="'scheduleType'"
[nzTooltipTitle]="'monitor.scheduleType.tip' | i18n"
+ >{{ 'monitor.scheduleType' | i18n }}
+ </nz-form-label>
+ <nz-form-control nzSpan="8" [nzErrorTip]="'validation.required' |
i18n">
+ <nz-select [(ngModel)]="monitor.scheduleType" name="scheduleType"
nzPlaceHolder="选择调度类型">
Review Comment:
The placeholder text '选择调度类型' is hardcoded in Chinese. It should use
internationalization like `{{ 'monitor.scheduleType.tip' | i18n }}` to support
multiple languages.
```suggestion
<nz-select [(ngModel)]="monitor.scheduleType" name="scheduleType"
[nzPlaceHolder]="'monitor.scheduleType.tip' | i18n">
```
##########
hertzbeat-collector/hertzbeat-collector-common/src/main/java/org/apache/hertzbeat/collector/timer/TimerDispatcher.java:
##########
@@ -153,9 +168,36 @@ public void responseSyncJobData(long jobId,
List<CollectRep.MetricsData> metrics
eventListener.response(metricsDataTemps);
}
}
-
+
@Override
public void destroy() throws Exception {
this.wheelTimer.stop();
}
+
+ public Long getNextExecutionInterval(Job job) {
+ if (ScheduleTypeEnum.CRON.getType().equals(job.getScheduleType()) &&
job.getCronExpression() != null && !job.getCronExpression().isEmpty()) {
+ try {
+ CronExpression cronExpression =
CronExpression.parse(job.getCronExpression());
+ ZonedDateTime nextExecutionTime =
cronExpression.next(ZonedDateTime.now());
+ long delay = Duration.between(ZonedDateTime.now(),
nextExecutionTime).toMillis();
+ // Convert to seconds and ensure non-negative
+ return Math.max(0, delay / 1000);
+ } catch (Exception e) {
+ log.error("Invalid cron expression: {}",
job.getCronExpression(), e);
+ // Fall back to interval scheduling if cron is invalid
+ return job.getInterval();
+ }
+ } else {
+ if (job.getDispatchTime() > 0) {
+ long spendTime = System.currentTimeMillis() -
job.getDispatchTime();
+ // Calculate remaining interval in seconds, preserving
millisecond precision
+ long intervalMs = job.getInterval() * 1000 - spendTime;
+ // Ensure non-negative
+ return Math.max(0, intervalMs / 1000);
+ }
+ return job.getInterval();
+ }
+ }
+
+
Review Comment:
Extra blank line should be removed to maintain consistent code formatting.
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]