Apache NiFi CRON表达式配置问题:非工作时段执行异常
Hey there, let's figure out why your processor is still running at 07:30 when you wanted it to stop at 07:00—your hunch about interval inclusivity is spot-on, but let's break down the specifics of how NiFi (which uses Quartz CRON under the hood) interprets these schedules.
The Root Cause: CRON Interval Logic
First, let's clarify how Quartz CRON handles hour ranges when the start value is higher than the end value (like 18-7). When you write * * 18-7 * * ?, NiFi/Quartz parses this as:
Run every second when the hour is 18 through 23, OR 0 through 7
That means your processor will keep triggering every second from 07:00:00 all the way to 07:59:59—explaining why you saw it running at 07:30. The interval includes the end value (7) in this case, which isn't what you want.
The Correct CRON Expression
To make the processor stop exactly at 07:00, you need to exclude the 7th hour entirely. Use this expression instead:
* * 18-23,0-6 * * ?
Let's break this down:
*: Every second*: Every minute18-23,0-6: Hours 18 (6 PM) through 23 (11 PM), AND 0 (midnight) through 6 (6:59 AM)*: Every day of the month*: Every month?: Ignore day-of-week (since we're already specifying day-of-month)
This ensures the last trigger happens at 06:59:59, and no triggers fire starting at 07:00:00.
Quick Checks to Confirm
- Use NiFi's CRON Preview: When editing your processor's scheduling, click the small preview icon next to the CRON field. This will show you the next 10 trigger times—verify that none fall after 06:59:59.
- Verify Timezone: Make sure your NiFi instance and the processor's scheduling timezone match your intended local time. A timezone mismatch could make the stop time appear off.
- Check Scheduling Strategy: Ensure the processor is set to CRON Driven (not Timer Driven) in the scheduling settings—Timer Driven uses fixed intervals and might not respect CRON boundaries as strictly.
内容的提问来源于stack exchange,提问作者Stellar Sword

