Schedule icon
Log icon

Executes flow on schedule trigger with a DayWeekInMonth when expression

Run a Kestra flow only on the last Saturday of every month using a Schedule trigger gated by a DayWeekInMonth `when` expression.

Categories
Core
id: schedule-condition-dayweekinmonth
namespace: company.team

triggers:
  - id: schedule
    type: io.kestra.plugin.core.trigger.Schedule
    cron: "0 11 * * *"
    when: "{{ isDayWeekInMonth(trigger.date, 'SATURDAY', 'LAST') }}"

tasks:
  - id: hello
    type: io.kestra.plugin.core.log.Log
    message: Demo for DayWeekInMonth condition

Plain cron expressions cannot express calendar rules like "the last Saturday of every month" or "the second Tuesday." This blueprint shows how Kestra solves that with a daily io.kestra.plugin.core.trigger.Schedule trigger combined with a when Pebble expression built on the isDayWeekInMonth() function, so the flow evaluates every day at 11am but only actually runs when the trigger date lands on the last Saturday of the month. It is the canonical pattern for monthly, position-based scheduling (week-of-month plus day-of-week) that raw cron syntax simply does not support.

How it works

  1. The schedule trigger uses cron 0 11 * * *, which fires the evaluation every day at 11am.
  2. The trigger's when expression calls isDayWeekInMonth({{ trigger.date }}, 'SATURDAY', 'LAST').
  3. Those arguments (SATURDAY, LAST) mean the function returns true only on the last Saturday of the month.
  4. When the expression evaluates to true, the single hello task (io.kestra.plugin.core.log.Log) runs and logs a demo message. On every other day the expression is false and no execution is created.

What you get

  • A reusable recipe for "Nth weekday of the month" scheduling without brittle cron hacks.
  • Exactly one execution per month (last Saturday at 11am) instead of 30+ skipped runs.
  • A clear, declarative example you can drop real tasks into.

Who it's for

  • Data and platform engineers running monthly close, reporting, or maintenance jobs.
  • Teams whose business calendar is defined by week-of-month rules rather than fixed dates.
  • Anyone migrating fragile cron-only schedules into Kestra.

Why orchestrate this with Kestra

A standard scheduler can fire on a day of the month, but it cannot natively express "the last Saturday" or "the first Monday." Kestra closes that gap with a declarative when Pebble expression on top of the Schedule trigger, and adds retries, backfills, full execution lineage, and event-driven triggers around the same flow. You get position-based calendar logic plus production-grade orchestration in one place.

Secrets

This flow uses no secrets. The hello task only logs a message, so no credentials are required.

Prerequisites

  • A running Kestra instance.
  • Permission to register flows and schedule triggers in your target namespace.

Quick start

  1. Copy this blueprint into your namespace.
  2. Save the flow so the Schedule trigger is registered.
  3. Wait for the next last Saturday at 11am, or use a backfill to validate the when expression immediately.
  4. Confirm an execution is created only on the matching date.

How to extend

  • Change the isDayWeekInMonth() arguments (day of week, and position: FIRST, SECOND, THIRD, FOURTH, LAST) for other calendar rules.
  • Replace the hello Log task with your real workload: a database job, an export, or a downstream subflow.
  • Adjust the cron time to shift the daily evaluation window.
  • Extend the when expression with and/or to further narrow when the flow runs.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.