-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[feat] Monitoring Center - Added cron expression support for scheduling type #3777
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
base: master
Are you sure you want to change the base?
Conversation
public Long getNextExecutionInterval(Job job) { | ||
if (ScheduleTypeEnum.CRON.getType().equals(job.getScheduleType()) && job.getCronExpression() != null && !job.getCronExpression().isEmpty()) { | ||
try { | ||
CronExpression cronExpression = new CronExpression(job.getCronExpression()); |
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.
FYI, using CronExpression
from spring-context
is probably preferable here. Quartz has slightly different cron semantics and would pull in an unnecessary extra dependency.
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.
Thanks! Already done. Removed Quartz and replaced it with Spring's built-in CronExpression parser. Keeps the same cron format but cleans up the dependencies.
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.
Pull Request Overview
This PR adds cron expression support for scheduling types in the Monitoring Center, providing an alternative to the existing second interval scheduling while maintaining backward compatibility.
- Added a new scheduling type selector with options for "Second Interval" (default) and "Cron Expression"
- Implemented cron expression parsing using Quartz for accurate next trigger time calculation
- Enhanced the UI to dynamically switch between interval and cron expression inputs with validation
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
web-app/src/assets/i18n/*.json | Added internationalization keys for schedule type and cron expression UI elements |
web-app/src/app/routes/monitor/monitor-form/monitor-form.component.* | Added schedule type selector and cron expression input with validation |
web-app/src/app/routes/monitor/monitor-data-table/monitor-data-table.component.html | Updated display to show cron expression or interval based on schedule type |
web-app/src/app/pojo/Monitor.ts | Added scheduleType and cronExpression properties to Monitor model |
hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/manager/Monitor.java | Added scheduleType and cronExpression fields to Monitor entity |
hertzbeat-common/src/main/java/org/apache/hertzbeat/common/entity/job/Job.java | Added scheduleType and cronExpression properties to Job entity |
hertzbeat-collector/hertzbeat-collector-common/src/main/java/org/apache/hertzbeat/collector/constants/ScheduleTypeEnum.java | Added enum for schedule types (INTERVAL, CRON) |
hertzbeat-collector/hertzbeat-collector-common/src/main/java/org/apache/hertzbeat/collector/timer/TimerDispatcher.java | Implemented cron expression parsing and next execution time calculation |
hertzbeat-collector/hertzbeat-collector-common/src/main/java/org/apache/hertzbeat/collector/timer/TimerDispatch.java | Added new cyclicJob method without parameters |
hertzbeat-collector/hertzbeat-collector-collector/src/main/java/org/apache/hertzbeat/collector/dispatch/CommonDispatcher.java | Updated to use new cyclicJob method for better scheduling |
hertzbeat-manager/src/main/java/org/apache/hertzbeat/manager/service/impl/MonitorServiceImpl.java | Updated to pass scheduleType and cronExpression to job definition |
hertzbeat-collector/hertzbeat-collector-common/src/test/java/org/apache/hertzbeat/collector/timer/TimerDispatcherTest.java | Added comprehensive test coverage for timer dispatcher functionality |
Comments suppressed due to low confidence (1)
hertzbeat-collector/hertzbeat-collector-common/src/main/java/org/apache/hertzbeat/collector/timer/TimerDispatcher.java:1
- This complex regex for cron validation is difficult to maintain and understand. Consider using a more readable approach with separate validation functions or leveraging the Spring CronExpression.parse() method for validation instead of regex.
/*
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@@ -0,0 +1,22 @@ | |||
package org.apache.hertzbeat.collector.constants; |
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.
Missing file header with Apache license. All Java files in this project should include the standard Apache License header.
Copilot uses AI. Check for mistakes.
>{{ 'monitor.scheduleType' | i18n }} | ||
</nz-form-label> | ||
<nz-form-control nzSpan="8" [nzErrorTip]="'validation.required' | i18n"> | ||
<nz-select [(ngModel)]="monitor.scheduleType" name="scheduleType" nzPlaceHolder="选择调度类型"> |
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.
The placeholder text '选择调度类型' is hardcoded in Chinese. It should use internationalization like {{ 'monitor.scheduleType.tip' | i18n }}
to support multiple languages.
<nz-select [(ngModel)]="monitor.scheduleType" name="scheduleType" nzPlaceHolder="选择调度类型"> | |
<nz-select [(ngModel)]="monitor.scheduleType" name="scheduleType" [nzPlaceHolder]="'monitor.scheduleType.tip' | i18n"> |
Copilot uses AI. Check for mistakes.
this.started = new AtomicBoolean(true); | ||
} | ||
|
||
|
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.
Extra blank line should be removed to maintain consistent code formatting.
Copilot uses AI. Check for mistakes.
} | ||
} | ||
|
||
|
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.
Extra blank line should be removed to maintain consistent code formatting.
Copilot uses AI. Check for mistakes.
What's changed?
Monitoring Center - Added cron expression support for scheduling type in add/edit monitor forms, with full backward compatibility.
For details:
scheduling type
Second Interval
Cron Expression
Checklist
Add or update API
I have configured

35 * * * * ?
. According to the monitoring history chart, metrics are collected after the 35th second.