Skip to content

Conversation

AlbertYang0801
Copy link

What's changed?

Monitoring Center - Added cron expression support for scheduling type in add/edit monitor forms, with full backward compatibility.

For details:

  • 1. Added a scheduler type selector on the task configuration page with two options: "Second Interval" (default) and "Cron Expression". When "Cron Expression" is selected, the input field dynamically switches to a Cron expression input with syntax guidance.
  • 2. Implemented real-time frontend validation for Cron expressions to ensure correctness.
  • 3. The monitoring task cycle display now supports Cron expressions.
  • 4. For tasks using Cron expressions, the system now uses Quartz to parse expressions and accurately calculate the next trigger time.
  • 5. Enhanced internationalization support for updated UI text to ensure proper display in multilingual environments.

scheduling type

  • Second Interval

    PixPin_2025-09-19_13-48-50 PixPin_2025-09-19_13-49-27
  • Cron Expression

    PixPin_2025-09-19_13-49-51 PixPin_2025-09-19_13-49-08

Checklist

Add or update API

I have configured 35 * * * * ? . According to the monitoring history chart, metrics are collected after the 35th second.
PixPin_2025-09-19_14-00-50

@AlbertYang0801 AlbertYang0801 changed the title Feat#3517 Feat#3517 Monitoring Center - Added cron expression support for scheduling type Sep 19, 2025
@AlbertYang0801 AlbertYang0801 changed the title Feat#3517 Monitoring Center - Added cron expression support for scheduling type [feat] Monitoring Center - Added cron expression support for scheduling type Sep 19, 2025
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());
Copy link
Contributor

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.

Copy link
Author

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.

@zqr10159 zqr10159 requested a review from Copilot September 25, 2025 14:59
Copy link
Contributor

@Copilot Copilot AI left a 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;
Copy link
Preview

Copilot AI Sep 25, 2025

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="选择调度类型">
Copy link
Preview

Copilot AI Sep 25, 2025

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.

Suggested change
<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);
}


Copy link
Preview

Copilot AI Sep 25, 2025

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.

Suggested change

Copilot uses AI. Check for mistakes.

}
}


Copy link
Preview

Copilot AI Sep 25, 2025

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.

Suggested change

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants