dhiaayachi / temporal

Temporal service
https://docs.temporal.io
MIT License
0 stars 0 forks source link

Schedule "StartAt" not used when calculating intervals? #128

Open dhiaayachi opened 2 weeks ago

dhiaayachi commented 2 weeks ago

Today is June 19th, 2024. If you create a schedule and specify "every 365 days" the result will be that the first run is on 2024-12-18 00:00:00. That's in 6 months. I've tried passing StartAt: 2025-06-19 but I get 2025-12-18 00:00:00 as a result.

I understand this may be known and as-designed behavior but it struck me as unexpected to ask for a 365 day interval, yet the first run is within the next 6 months.

I also don't see any way to achieve my desired result. Am I missing anything?

EDIT: I also can't use the offset to control this behavior because I don't know what the final calculation will be until the schedule is created.

Expected Behavior

In the example above, I'd prefer to have the schedule's first run be at my specified "StartAt". So, if I say:

"Start this workflow every 365 days with start at 2025-02-03 04:05:06", then the upcoming runs would look like:

Actual Behavior

When I pick 365 days as the interval, I seem to be getting a date 6 months in the future.

Steps to Reproduce the Problem

  1. Go to temporal UI and add a schedule.
  2. Choose 365 days and save.
  3. Check the schedule's upcoming runs.

Specifications

dhiaayachi commented 6 days ago

Temporal Schedule - Unexpected Interval Behavior

This issue appears to stem from the way Temporal currently interprets the combination of an interval and a start time when creating a schedule.

The problem:

Explanation:

The behavior you're observing is likely due to Temporal's internal implementation of interval-based schedules. When you specify an interval, it calculates the next occurrence of that interval after the provided "StartAt" time. In your case, specifying "every 365 days" with a "StartAt" of June 19th results in the next occurrence of the interval being December 18th, which is indeed 6 months later.

Temporal's Expected Behavior:

Temporal currently aligns the first run of a schedule with the next occurrence of the specified interval after the provided "StartAt" time. This is a different behavior from a cron schedule where the "StartAt" time directly dictates the initial run, while subsequent runs follow the cron expression.

Possible Workarounds:

As of now, Temporal lacks a direct way to override this behavior and have the first run strictly follow the specified "StartAt" time while adhering to the interval. Here are some potential workarounds:

Future Enhancements:

You can submit a feature request to Temporal to improve schedule creation functionality and allow users to specify the exact start time for the first run while adhering to the desired interval.

References:

Note:

Temporal is constantly evolving, so these limitations may be addressed in future releases. Keep an eye out for updates to the Temporal documentation and SDKs for any new features or changes related to schedule management.

dhiaayachi commented 6 days ago

Thanks for reporting this! It seems you've stumbled upon an issue with how Temporal handles schedules with a 365-day interval.

Currently, Temporal calculates the first run of a schedule based on the time it's created, even if you specify a StartAt time. This behavior might be unexpected, as it doesn't directly align with the intended StartAt time.

Here's a potential workaround:

We understand this is a known issue and are actively working on improving the scheduling behavior to better align with user expectations.

Let us know if you have any other questions!