Vibescript Showcase

Digest schedule

Schedule digest jobs with cadence enums, Duration windows, and template-driven subjects.

Showcase
Source showcase/notifications/digest_schedule.vibe
# title: Digest schedule
# category: Vibescript Showcase
# difficulty: Showcase
# summary: Schedule digest jobs with cadence enums, Duration windows, and template-driven subjects.
# description: This example uses semantic cadence values and deterministic times to keep notification scheduling logic compact and legible.
# tags: notifications, durations, enums, templates
# vibe: 0.2

enum DigestCadence
  Hourly
  Daily
  Weekly
end

def cadence_window(cadence: DigestCadence) -> duration
  if cadence == DigestCadence::Hourly
    1.hour
  elsif cadence == DigestCadence::Daily
    24.hours
  else
    7.days
  end
end

def digest_job(channel_id: string, cadence: DigestCadence, anchor: time) -> hash
  window = cadence_window(cadence)

  {
    channel_id: channel_id,
    cadence: cadence.name,
    window: window.iso8601,
    next_run: window.after(anchor).format("2006-01-02T15:04:05Z"),
    subject: "{{cadence}} digest for {{channel}}".template({ cadence: cadence.name, channel: channel_id })
  }
end

def run
  anchor = Time.at(1700900000)

  {
    hourly: digest_job("ops-alerts", DigestCadence::Hourly, anchor),
    weekly: digest_job("revenue-updates", DigestCadence::Weekly, anchor)
  }
end
Output
Press run to execute run from this example.
showcase idiomatic-vibescript notifications durations enums templates browser-runner