Skip to content
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

[kie-roadmap-119] Scheduled jobs do not keep configured execution time #2292

Merged
merged 3 commits into from Aug 1, 2023

Conversation

martinweiler
Copy link
Contributor

When scheduling a LogCleanupCommand with NextRun=1d, the actual execution time for the next run is calculated as (current command execution time + nextRun value). Over time, this can lead to the scheduled execution time to slip, ie. a job scheduled initially at 00:00 gets executed at 00:10, and the execution could be outside of a designated maintenance window.

The expectation is that subsequent executions happen at the defined start time + nextRun value, ie. a job scheduled initially at 00:00 with NextRun=1d should always run at 00:00, regardless of how long it takes to execute it.

@sonarcloud
Copy link

sonarcloud bot commented Jun 8, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

92.3% 92.3% Coverage
0.0% 0.0% Duplication

Copy link
Member

@gmunozfe gmunozfe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martinweiler Good work! I think there's an edge scenario that can be handled (nextScheduleTimeAdd is negative after subtraction). Other two minor comments and also you could rebase it as we are in the next snapshot now.


String nextRun = (String) ctx.getData("NextRun");
if (nextRun != null) {
nextScheduleTimeAdd = DateTimeUtils.parseDateAsDuration(nextRun) - calculateExecutionTimeInMillis(ctx);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suppose that the subtraction is negative (because the cleanup operation lasts too long or the interval is very short): in that case, the nextScheduleTimeAdd is negative, and therefore getScheduleTime will return null, without scheduling any other time.
I think this edge scenario could be handled as well, wdyt? (also a test with more delay to verify that the cleanup execution is not stopped).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gmunozfe thanks for the input, that makes sense. I added the check that in case there is an overlap (previous execution took longer than nextRun value), the next execution is scheduled immediately. Also added a new test case for this scenario.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martinweiler thanks, this looks great!

@sonarcloud
Copy link

sonarcloud bot commented Jul 27, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

95.7% 95.7% Coverage
0.0% 0.0% Duplication

@gmunozfe gmunozfe self-requested a review August 1, 2023 09:10
Copy link
Member

@gmunozfe gmunozfe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, astounding work @martinweiler !
Could you add the labels for automatic backporting to 7.67.x and blue? I think with that it's ready to merge

@martinweiler martinweiler added backport-7.67.x Generate backport PR for 7.67.x branch backport-7.67.x-blue Generate backport PR for 7.67.x-blue branch labels Aug 1, 2023
@martinweiler
Copy link
Contributor Author

Thank you @gmunozfe ! I have added the labels now.

@fjtirado fjtirado merged commit c4be121 into kiegroup:main Aug 1, 2023
9 checks passed
github-actions bot pushed a commit that referenced this pull request Aug 1, 2023
#2292)

* [kie-roadmap-119] Scheduled jobs do not keep configured execution time

* [kie-roadmap-119] Make sure job gets rescheduled even if execution time exceeds nextRun value
github-actions bot pushed a commit that referenced this pull request Aug 1, 2023
#2292)

* [kie-roadmap-119] Scheduled jobs do not keep configured execution time

* [kie-roadmap-119] Make sure job gets rescheduled even if execution time exceeds nextRun value
fjtirado pushed a commit that referenced this pull request Aug 2, 2023
#2292) (#2309)

* [kie-roadmap-119] Scheduled jobs do not keep configured execution time

* [kie-roadmap-119] Make sure job gets rescheduled even if execution time exceeds nextRun value

Co-authored-by: Martin Weiler <mweiler@redhat.com>
fjtirado pushed a commit that referenced this pull request Aug 2, 2023
#2292) (#2308)

* [kie-roadmap-119] Scheduled jobs do not keep configured execution time

* [kie-roadmap-119] Make sure job gets rescheduled even if execution time exceeds nextRun value

Co-authored-by: Martin Weiler <mweiler@redhat.com>
fjtirado pushed a commit to fjtirado/jbpm that referenced this pull request Aug 17, 2023
kiegroup#2292)

* [kie-roadmap-119] Scheduled jobs do not keep configured execution time

* [kie-roadmap-119] Make sure job gets rescheduled even if execution time exceeds nextRun value
fjtirado pushed a commit to fjtirado/jbpm that referenced this pull request Sep 15, 2023
kiegroup#2292)

* [kie-roadmap-119] Scheduled jobs do not keep configured execution time

* [kie-roadmap-119] Make sure job gets rescheduled even if execution time exceeds nextRun value
fjtirado pushed a commit to fjtirado/jbpm that referenced this pull request Sep 15, 2023
kiegroup#2292)

* [kie-roadmap-119] Scheduled jobs do not keep configured execution time

* [kie-roadmap-119] Make sure job gets rescheduled even if execution time exceeds nextRun value
fjtirado pushed a commit to fjtirado/jbpm that referenced this pull request Nov 7, 2023
kiegroup#2292)

* [kie-roadmap-119] Scheduled jobs do not keep configured execution time

* [kie-roadmap-119] Make sure job gets rescheduled even if execution time exceeds nextRun value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-7.67.x Generate backport PR for 7.67.x branch backport-7.67.x-blue Generate backport PR for 7.67.x-blue branch
Projects
None yet
4 participants