Workflow Schedule questions

We are starting to use Temporal’s Scheduled Workflows a lot more. (We used to use cron workflows in the past.) In one of the use cases, the schedule will be provided by users, i.e. users can decide to run certain workflows either once immediately, once at a specified time in the future, or on a specified interval.

I’ve got a couple of questions related to this:

  1. The docs mention that it’s possible to limit the number of actions executed by a schedule:

A Schedule can be limited to a certain number of scheduled Actions (that is, not trigger immediately). After that it will act as if it were paused.

But it’s not clear from the ScheduleSpec how to actually do that. What am I missing?

  1. Is there some way to verify a schedule/calendar spec first before we actually go ahead and schedule the workflow? The docs for the ScheduleSpec#encode method refer to a verify method, but that doesn’t seem to exist. (Or is not exposed.)

  2. What’s the best way to specify a schedule that should run once at a specified time in the future? The only way we could see is to use a calendar-based schedule, e.g. { calendar: [{ year: 2023, month: 'NOVEMBER', dayOfMonth: 31, hour: 8 }] }. But we would like to be able to tell whether a schedule will run exactly once or more than once, and this form makes that a bit difficult, unless we implement our own parsing logic for the CalendarSpec. (Not too difficult, just wondering if there is an easier/better way.)

Hello!

  1. Look at ScheduleOptions.state.remainingActions.

  2. No, there is no way to verify a calendar spec prior to creating it at the moment. I’m surprised to see a reference to a verify method in the doc. That’s an error, I’ll fix it. Thanks for pointing this out.

  3. I’m not sure if I correctly understand your question. Specifying a calendar using year+month+day of month+hour seems a pretty reliable way of ensuring that your scheduled action will run only once… Why would you want to validate that? Now, if you mean that you are talking calendar spec in general, then the easiest thing to do would be to create that schedule on the server, then describe it (scheduleHandle.describe()); in the ScheduleDescription.info.nextActionTimes field, you will get the exact time of upcoming executions (up to 10). If there is less than 10 entries in that list, then you know exactly how many time that schedule will execute. If there is no entries at all, it means the calendar spec was somehow invalid (eg. it only match on Feb 30th or dates in the past).

1 Like
  1. Look at ScheduleOptions.state.remainingActions.

Ah, thanks! Somehow I had assume that state is a read-only property from the client perspective.

  1. No, there is no way to verify a calendar spec prior to creating it at the moment.

Got it.

  1. […] Specifying a calendar using year+month+day of month+hour seems a pretty reliable way of ensuring that your scheduled action will run only once… Why would you want to validate that?

It’s not so much about validating the schedule when the user is creating it. It’s about displaying a bunch of schedules back to the user, and being able to mark the difference between recurring schedules and one-time, deferred schedules. But I think between remainingActions and nextActionTimes we probably have enough information to show the current state of each schedule to the user.

This was very helpful! Thank you! :pray:

1 Like