1import type * as scheduler from "@distilled.cloud/aws/scheduler";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { Role } from "../IAM/Role.ts";
5import type { ScheduleGroup } from "./ScheduleGroup.ts";
6
7/**
8 * The schedule target passed at runtime. `RoleArn` defaults to the execution
9 * role the binding was constructed with, so callers normally omit it.
10 */
11export interface UpdateScheduleTarget extends Omit<
12 scheduler.Target,
13 "RoleArn"
14> {
15 /**
16 * Execution role EventBridge Scheduler assumes to invoke the target.
17 * @default the execution role bound via `UpdateSchedule(role)`
18 */
19 RoleArn?: string;
20}
21
22export interface UpdateScheduleRequest extends Omit<
23 scheduler.UpdateScheduleInput,
24 "GroupName" | "Target" | "FlexibleTimeWindow"
25> {
26 /**
27 * Target the schedule invokes when it fires. The bound execution role is
28 * injected as `RoleArn` unless the request overrides it.
29 */
30 Target: UpdateScheduleTarget;
31 /**
32 * Flexible time window configuration.
33 * @default { Mode: "OFF" }
34 */
35 FlexibleTimeWindow?: scheduler.FlexibleTimeWindow;
36}
37
38/**
39 * Runtime binding for `scheduler:UpdateSchedule`.
40 *
41 * Pairs with {@link CreateSchedule} for the dynamic-scheduling pattern: a
42 * deployed Lambda reschedules or pauses schedules it minted at runtime (push
43 * a reminder back, disable a recurring job). `UpdateSchedule` is a full PUT —
44 * unspecified fields are reset to their defaults, so send the complete
45 * desired configuration.
46 *
47 * Like {@link CreateSchedule}, the binding is constructed with the schedule
48 * **execution role** and optionally a scoping `ScheduleGroup`; it contributes
49 * both `scheduler:UpdateSchedule` on the group's schedule ARN pattern and
50 * `iam:PassRole` on the execution role.
51 * ### Updating Schedules At Runtime
52 * **Example:** Reschedule A Reminder
53 * ```typescript
54 * const updateSchedule = yield* AWS.Scheduler.UpdateSchedule(role);
55 *
56 * // runtime: push the reminder back a day (full PUT — resend the target)
57 * yield* updateSchedule({
58 * Name: `reminder-${userId}`,
59 * ScheduleExpression: "at(2026-01-02T00:00:00)",
60 * ActionAfterCompletion: "DELETE",
61 * Target: {
62 * Arn: yield* queueArn,
63 * Input: JSON.stringify({ userId }),
64 * },
65 * });
66 * ```
67 *
68 * **Example:** Scope Updates To A Schedule Group
69 * ```typescript
70 * const updateSchedule = yield* AWS.Scheduler.UpdateSchedule(role, group);
71 * ```
72 *
73 * @binding
74 */
75export interface UpdateSchedule extends Binding.Service<
76 UpdateSchedule,
77 "AWS.Scheduler.UpdateSchedule",
78 <R extends Role>(
79 executionRole: R,
80 group?: ScheduleGroup,
81 ) => Effect.Effect<
82 (
83 request: UpdateScheduleRequest,
84 ) => Effect.Effect<
85 scheduler.UpdateScheduleOutput,
86 scheduler.UpdateScheduleError
87 >
88 >
89> {}
90export const UpdateSchedule = Binding.Service<UpdateSchedule>(
91 "AWS.Scheduler.UpdateSchedule",
92);