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

[Bug] First schedule action started using triggerImmediately flag does not honor the schedule's overlap policy #1594

Open
jhecking opened this issue Jan 8, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@jhecking
Copy link
Contributor

jhecking commented Jan 8, 2025

What are you really trying to do?

I'm creating a new schedule and I want to trigger it immediately. I don't want any overlapping schedule runs.

Describe the bug

I'm creating a new schedule using a combination of ScheduleOverlapPolicy.BUFFER_ONE and triggerImmediately: true, i.e.

export async function schedulePeriodicWorkflowExecution(
  action: ScheduleOptionsStartWorkflowAction<Workflow>,
  scheduleId: string,
  cronExpression: string,
) {
  const client = await getScheduleClient()
  const spec = { cronExpressions: [cronExpression] }
  return client.create({
    action,
    spec,
    scheduleId,
    policies: {
      overlap: ScheduleOverlapPolicy.BUFFER_ONE,
    },
    state: {
      triggerImmediately: true,
    },
  })
}

If the initial schedule run, started via triggerImmediately: true takes long enough that the next run gets triggered as per the provided cron schedule, that second schedule run does not get buffered but gets executed immediately.

I believe this is because the initial schedule run always gets executed with a default "AllowAll" overlap policy:

initialPatch: {
triggerImmediately: opts.state?.triggerImmediately
? { overlapPolicy: temporal.api.enums.v1.ScheduleOverlapPolicy.SCHEDULE_OVERLAP_POLICY_ALLOW_ALL }
: undefined,

A possible work-around is to create the schedule and then immediately trigger it ourselves using the correct overlap policy, i.e.

export async function schedulePeriodicWorkflowExecution(
  action: ScheduleOptionsStartWorkflowAction<Workflow>,
  scheduleId: string,
  cronExpression: string,
) {
  const client = await getScheduleClient()
  const spec = { cronExpressions: [cronExpression] }
  const handle = client.create({
    action,
    spec,
    scheduleId,
    policies: {
      overlap: ScheduleOverlapPolicy.BUFFER_ONE,
    },
  })
  await handle.trigger(ScheduleOverlapPolicy.BUFFER_ONE)
  return handle
}

But I think triggerImmediately: true should honor the schedule's overlap policy instead of defaulting to the "AllowAll" policy.

Minimal Reproduction

https://github.com/jhecking/samples-typescript/tree/schedules-trigger-immediately-overlapping/schedules-trigger-immediately-overlapping

Environment/Versions

  • Temporal Version: 1.11.2

Additional context

n/a

@jhecking jhecking added the bug Something isn't working label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant