@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 111 lines 4.15 KB
Raw
1 import type * as Effect from "effect/Effect";
2 import type * as Stream from "effect/Stream";
3 import {
4 consumeBusEvents,
5 type EventRecord,
6 type EventRouteProps,
7 } from "../EventBridge/EventSource.ts";
8
9 /**
10 * The `detail` payload AWS Elemental MediaPackage v2 delivers to
11 * EventBridge when a live-to-VOD harvest job succeeds or fails
12 * (detail-type `MediaPackageV2 HarvestJob Notification`).
13 */
14 export interface MediaPackageV2HarvestJobEventDetail {
15 /** The harvest job the notification is about. */
16 harvestJob: {
17 /** Name of the harvest job. */
18 harvestJobName: string;
19 /** ARN of the harvest job. */
20 arn: string;
21 /** Terminal status: `COMPLETED` or `FAILED`. */
22 status: string;
23 /** Channel group the harvested endpoint belongs to. */
24 channelGroupName: string;
25 /** Channel the harvested endpoint belongs to. */
26 channelName: string;
27 /** Origin endpoint the content was harvested from. */
28 originEndpointName: string;
29 /** Human-readable outcome (e.g. the failure reason). */
30 message?: string;
31 /** The harvested time window. */
32 scheduleConfiguration?: { startTime?: string; endTime?: string };
33 /** Where the VOD asset was written. */
34 destination?: {
35 s3Destination?: { bucketName?: string; destinationPath?: string };
36 };
37 /** Additional fields (the schema grows over time). */
38 [key: string]: unknown;
39 };
40 }
41
42 /** A MediaPackage v2 harvest-job EventBridge event delivered to the handler. */
43 export type MediaPackageV2HarvestJobEvent = EventRecord<MediaPackageV2HarvestJobEventDetail>;
44
45 export interface HarvestJobEventSourceProps extends EventRouteProps {
46 /**
47 * Logical id for the backing EventBridge rule.
48 * @default "MediaPackageV2HarvestJobEvents"
49 */
50 id?: string;
51 /**
52 * Restrict to notifications about specific harvest jobs (matched against
53 * the event's top-level `resources`, which contains the harvest job ARN
54 * `{endpointArn}/harvestJob/{name}`). Prefix patterns are not supported
55 * here — filter in the handler for per-endpoint routing.
56 */
57 harvestJobArns?: readonly string[];
58 }
59
60 /**
61 * Event source connecting AWS Elemental MediaPackage v2 harvest-job
62 * notifications to the hosting compute. MediaPackage publishes an event to
63 * the account's default EventBridge bus (source `aws.mediapackagev2`,
64 * detail-type `MediaPackageV2 HarvestJob Notification`) when a live-to-VOD
65 * harvest job completes or fails; this subscribes the host Function to
66 * those events so it can publish the exported clip — or alert on a failed
67 * export — without polling `GetHarvestJob`.
68 *
69 * MediaPackage publishes to EventBridge automatically — no additional
70 * resource is created besides the EventBridge rule targeting the host.
71 * Provide the host-specific implementation layer (e.g.
72 * `AWS.Lambda.EventSource`) on the Function effect.
73 *
74 * ### Consuming Harvest Job Events
75 * **Example:** Publish a Clip When Its Harvest Job Completes
76 * ```typescript
77 * import * as AWS from "@alchemy.run/aws";
78 *
79 * export default ClipPublisher.make(
80 * { main: import.meta.url },
81 * Effect.gen(function* () {
82 * yield* AWS.MediaPackageV2.consumeHarvestJobEvents({}, (events) =>
83 * Stream.runForEach(events, (event) =>
84 * event.detail.harvestJob.status === "COMPLETED"
85 * ? Effect.log(
86 * `clip ready: ${event.detail.harvestJob.destination?.s3Destination?.destinationPath}`,
87 * )
88 * : Effect.log(`harvest failed: ${event.detail.harvestJob.message}`),
89 * ),
90 * );
91 * return {};
92 * }).pipe(Effect.provide(AWS.Lambda.EventSource)),
93 * );
94 * ```
95 */
96 export const consumeHarvestJobEvents = <StreamReq = never, Req = never>(
97 props: HarvestJobEventSourceProps,
98 process: (
99 events: Stream.Stream<MediaPackageV2HarvestJobEvent, never, StreamReq>,
100 ) => Effect.Effect<void, never, Req>,
101 ) =>
102 consumeBusEvents(
103 props.id ?? "MediaPackageV2HarvestJobEvents",
104 {
105 source: ["aws.mediapackagev2"],
106 "detail-type": ["MediaPackageV2 HarvestJob Notification"],
107 ...(props.harvestJobArns !== undefined ? { resources: [...props.harvestJobArns] } : {}),
108 },
109 { description: props.description, state: props.state },
110 process,
111 );