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

Scheduler: fix Trigger#getNextFireTime() for cron-based jobs #41778

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

@mkouba
Copy link
Contributor Author

mkouba commented Jul 9, 2024

@alanmscott it would be great if you could test this PR!

@quarkus-bot

This comment has been minimized.

@alanmscott
Copy link

alanmscott commented Jul 9, 2024

Hi @mkouba

I've had a test with the new SimpleScheduler. Whilst it is casting the Instant into the value correctly, it still has the problem where it can return a "nextFireTime" in the past.

E.g.

USING: cron = "0 35 12 ? * * *";

2024-07-09 11:58:25,719 INFO  [org.exa.TestScheduler] (Quarkus Main Thread) NextFireTimes:
2024-07-09 11:58:25,721 INFO  [org.exa.TestScheduler] (Quarkus Main Thread) TestJob1(UTC     )=2024-07-09T12:35:00Z / 2024-07-09T12:35:00Z[UTC]
2024-07-09 11:58:25,722 INFO  [org.exa.TestScheduler] (Quarkus Main Thread) TestJob2(London  )=2024-07-09T11:35:00Z / 2024-07-09T12:35:00+01:00[Europe/London]
2024-07-09 11:58:25,722 INFO  [org.exa.TestScheduler] (Quarkus Main Thread) TestJob3(Berlin  )=2024-07-09T10:35:00Z / 2024-07-09T12:35:00+02:00[Europe/Berlin]
2024-07-09 11:58:25,722 INFO  [org.exa.TestScheduler] (Quarkus Main Thread) TestJob4(Istanbul)=2024-07-09T09:35:00Z / 2024-07-09T12:35:00+03:00[Europe/Istanbul]
2024-07-09 11:58:25,722 INFO  [org.exa.TestScheduler] (Quarkus Main Thread) compareTo result1-2=1     <-- should be greater than 0
2024-07-09 11:58:25,723 INFO  [org.exa.TestScheduler] (Quarkus Main Thread) compareTo result2-3=1     <-- should be greater than 0
2024-07-09 11:58:25,723 INFO  [org.exa.TestScheduler] (Quarkus Main Thread) compareTo result3-4=1     <-- should be greater than 0

As you can see, the local time (London time) is 09/07/2024 11:58.
The UTC and London nextFireTime is perfectly correct, but for the others, it shows an almost sensible time, but it's actually in the past.
i.e. at 11:58 in London, the time in Berlin is 12:58, so the nextFireTime should be 10/07/2024 12:35
Similarly, for Istanbul, the time is 13:58, so the nextFireTime should 10/07/2024 12:35.

Is perhaps a problem with the value being returned by the underlying cronutils library?

@mkouba
Copy link
Contributor Author

mkouba commented Jul 9, 2024

Is perhaps a problem with the value being returned by the underlying cronutils library?

Hi @alanmscott, thanks a lot for testing this PR!

You're right and I don't think it's the problem of cronutils. It's the way we adapt the next fire time because we retain the local date-time and change the timezone. Which is not correct. Let me try to fix that. Oh, timezones 🤦.

@mkouba
Copy link
Contributor Author

mkouba commented Jul 9, 2024

@alanmscott Ok, another attempt. Note that I've removed the comparison of instants because it really depends on the current time.

@alanmscott
Copy link

I think the latest change looks good. It's returning what I'd expect for the test harness:

USING Cron = "0 06 17 ? * * *";

2024-07-09 16:05:36,103 INFO  [org.exa.TestScheduler] (Quarkus Main Thread) NextFireTimes:
2024-07-09 16:05:36,106 INFO  [org.exa.TestScheduler] (Quarkus Main Thread) TestJob1(UTC     )=2024-07-09T17:06:00Z / 2024-07-09T17:06:00Z[UTC]
2024-07-09 16:05:36,107 INFO  [org.exa.TestScheduler] (Quarkus Main Thread) TestJob2(London  )=2024-07-09T16:06:00Z / 2024-07-09T17:06:00+01:00[Europe/London]
2024-07-09 16:05:36,107 INFO  [org.exa.TestScheduler] (Quarkus Main Thread) TestJob3(Berlin  )=2024-07-09T15:06:00Z / 2024-07-09T17:06:00+02:00[Europe/Berlin]
2024-07-09 16:05:36,107 INFO  [org.exa.TestScheduler] (Quarkus Main Thread) TestJob4(Istanbul)=2024-07-10T14:06:00Z / 2024-07-10T17:06:00+03:00[Europe/Istanbul]

Which is right. 17:06 for London = 18:06 for Berlin, so that is still "today", but has passed for Istanbul which is now "tomorrow".
I noted that the trigger still executed for "job3" also, demonstrating the triggering is unchanged and correct.

Fantastic, thank you!!!

@quarkus-bot
Copy link

quarkus-bot bot commented Jul 9, 2024

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 30af1a6.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

@manovotn manovotn merged commit 16e9ea3 into quarkusio:main Jul 10, 2024
32 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.13 - main milestone Jul 10, 2024
@gsmet gsmet modified the milestones: 3.13 - main, 3.12.3 Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment