-
Notifications
You must be signed in to change notification settings - Fork 556
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
feat(engine): support cron expression for timer cycle. #9674
Conversation
Hi @saig0. I try to fix this, please review my code and provide some comments. 🙇 |
bpmn-model/src/main/java/io/camunda/zeebe/model/bpmn/util/time/corn/BitsCronField.java
Fixed
Show fixed
Hide fixed
bpmn-model/src/main/java/io/camunda/zeebe/model/bpmn/util/time/corn/BitsCronField.java
Fixed
Show fixed
Hide fixed
Thanks for this @lzgabel ❤️ I'd like to first find an answer to #9673 (comment) before I'll review this. Hope that's okay |
@lzgabel As we've made a decision on the solution (i.e. we would like to continue with your original approach), I'll do my best to review this soon. |
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 @lzgabel another great contribution! 🎉
❌ There are a few things to change before we can accept this 🏗️ , but I'm very excited about this PR.
🔧 To ease the review, please separate the changes over multiple commits. For example, the CRON parsing code can be in a single commit, and the code that uses the CRON parser in the engine can be another.
bpmn-model/src/main/java/io/camunda/zeebe/model/bpmn/util/time/corn/BitsCronField.java
Outdated
Show resolved
Hide resolved
...java/io/camunda/zeebe/engine/processing/deployment/model/validation/TimerValidationTest.java
Outdated
Show resolved
Hide resolved
engine/src/test/java/io/camunda/zeebe/engine/processing/timer/TimerStartEventTest.java
Outdated
Show resolved
Hide resolved
702017b
to
ace6c7f
Compare
Hi @korthout . Sorry for the long wait. I've separated this change into multiple commits. Please check this out. 🙇 |
Hi @lzgabel I didn't find time for this today and I'm out-of-office tomorrow. I'll do my best to look at it when I'm back. |
Hi @lzgabel Thanks for splitting up the changes into separate commits 👍 I had another look at our options, and I really prefer to use a library over copying third-party code into our repository for this. Looking around, https://github.com/jmrozanec/cron-utils is really promising. It's trusted by several popular projects, has a small footprint, and seems actively maintained. I understood from you that there was some downside to it. As far as I can see we can make it use the SPRING CronDefinition, which would then behave the same as the copied code. After giving it a try, I think you can easily create a simple new @Override
public long getDueDate(final long epochMillis) {
final var cron =
new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.SPRING))
.parse("cron expression");
return ExecutionTime.forCron(cron)
.nextExecution(
ZonedDateTime.ofInstant(Instant.ofEpochMilli(epochMillis), ZoneId.systemDefault()))
.map(ZonedDateTime::toInstant)
.map(Instant::toEpochMilli)
.orElse(epochMillis);
} I think this would work correctly. Please let me know what you think. |
Hi @korthout . Usually this library satisfies most of our scenarios. As I mentioned before, this class library is not perfect enough and may not be able to solve some of our specific scenarios. For example, we want to start execution at 0:00 on the third last day of each month : Of course, this depends on how granular the engine supports cron expression parsing, and it may require the team to participate in discussions to come to a conclusion. |
That's strange, the README explains it does, but then it doesn't.
They are aware and plan to offer support for this What do you think? |
LGTM. 👍
❓ Currently the class library is planning to upgrade the jdk version. So I want to ask if the jdk version (currently using jdk8) used by |
No we can't upgrade those as they are consumed by users that might depend on those Java versions. But does the crontimer really have to exist in that module? I think it's possible to introduce it to the engine module. Then the dependency exists only there. |
Hi @korthout . I really thought about it in the early days, but then I gave up because of the idea of unified module processing. 😄 Of course a big thanks to cron-utils for such an amazing contribution. 💯 |
ace6c7f
to
b834db1
Compare
Hi @korthout . Do you have any other opinion on this? 🤔 |
Hi @lzgabel Sorry about that, I completely missed your question. 🙇
I'm not familiar with this. Could you explain?
If you import a class from this library in the engine, you'll notice that
We would like to keep the spring dependencies out of the engine. However, I'm fine with adding the cron-utils dependency (I'm a bit of a hypocrite I guess 😆). If we really dislike this direct dependency in the engine module, we could move the cron integration into a separate module. However, I don't see a need for this now. |
Hi @korthout . Sorry for the inconvenience caused by my unclear description. 🙇
What I want to express is that since the engine has indirectly introduced the |
engine/src/main/java/io/camunda/zeebe/engine/processing/timer/CronTimer.java
Outdated
Show resolved
Hide resolved
Hi @korthout . I've completed this change, please check this out. 🙇 BTW, I'll deal with code conflicts after this review. ❤️ |
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.
This looks great! 💯 Thanks for the changes @lzgabel.
Please consider my last comment and resolve the conflict. And then we should be ready to merge. 🚀
engine/src/main/java/io/camunda/zeebe/engine/processing/timer/CronTimer.java
Outdated
Show resolved
Hide resolved
6a1d849
to
04114e4
Compare
Hi @korthout . I've resolved the conflict, please check this out. 🙇 |
Test Results 805 files + 2 1 errors 804 suites +2 1h 37m 25s ⏱️ + 6m 0s For more details on these parsing errors and failures, see this check. Results for commit 04114e4. ± Comparison against base commit d672c7e. |
Oops! Flaky tests encountered. 😆 |
Seems to be this one. Was looked at 2 days ago, but closed because unable to reproduce. Let's see if it happens more often. |
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.
👍 LGTM
💯 kudos for this massively important contribution! It's really great that we now support cron expressions in timer cycles ⏲️
❓ Can you please open an issue in https://github.com/camunda/camunda-platform-docs to expand the documentation on timer cycles?
❓ Can you please open an issue in https://github.com/camunda/camunda-modeler that the validation for timer cycles has changed?
- I'll add this topic to the release notes
bors merge
Build succeeded: |
Hi @korthout . There are still some open issues that need our attention, such as camunda/camunda-modeler#2368, so I can't confirm the entire verification range. Could you take it over now? |
Description
As a user, I want to be able to set the
cron expression
fortimer cycle
.Parse the given crontab expression string. The string has six single space-separated time and date fields:
The following rules apply:
Example expressions:
of the month at midnight
Related issues
closes #9673
Definition of Done
Not all items need to be done depending on the issue and the pull request.
Code changes:
backport stable/1.3
) to the PR, in case that fails you need to create backports manually.Testing:
Documentation:
Please refer to our review guidelines.