From 2859955095020b07909b079d34be8a80e7f58ecd Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Thu, 2 Jul 2026 11:10:07 -0700 Subject: Backup --- src/canary/job.ts | 18 +----------------- src/publisher/index.ts | 23 ----------------------- src/util/scheduler.ts | 28 +++++++++++++++++++++------- 3 files changed, 22 insertions(+), 47 deletions(-) delete mode 100644 src/publisher/index.ts (limited to 'src') diff --git a/src/canary/job.ts b/src/canary/job.ts index 61af876..a654417 100644 --- a/src/canary/job.ts +++ b/src/canary/job.ts @@ -1,20 +1,6 @@ -import { D } from "../util"; - -export interface PingJob { - hosts: string[]; -} - export interface Retry { retries: number; - interval: D.Duration; -} - -export interface HealthCheckJob { - healthcheck_routes: string[]; -} - -export interface DnsJob { - resolutions: { [key: string]: string }; + interval: number; } export interface EmailInstruction { @@ -37,5 +23,3 @@ export interface EmailJob { to: EmailToInstruction; readRetry: Retry; } - -export type Job = EmailJob | PingJob | HealthCheckJob | DnsJob; diff --git a/src/publisher/index.ts b/src/publisher/index.ts deleted file mode 100644 index f37e108..0000000 --- a/src/publisher/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { D } from "../util"; - -export enum PublisherType { - DISCORD = "discord", - NTFY = "ntfy", -} - -export interface DiscordPost { - webhook: string; - role_id: string; -} - -export interface NtfyPost { - webhook: string; -} - -export type PublisherPost = DiscordPost | NtfyPost; - -export interface Publisher { - type: PublisherType; - at: D.Duration; - post: PublisherPost; -} diff --git a/src/util/scheduler.ts b/src/util/scheduler.ts index 9f9f594..476aca0 100644 --- a/src/util/scheduler.ts +++ b/src/util/scheduler.ts @@ -1,24 +1,38 @@ import * as TE from "fp-ts/lib/TaskEither"; -import { pipe } from "fp-ts/lib/function"; -import type { Schedule } from "../canary"; +import { pipe, identity } from "fp-ts/lib/function"; +import type { Job, Schedule } from "../canary"; +import * as RA from "fp-ts/lib/ReadonlyArray"; +import * as T from "fp-ts/lib/Task"; +import type { Separated } from "fp-ts/lib/Separated"; interface ScheduledJob { id: string; - execute: TE.TaskEither; + execute: () => TE.TaskEither; at: Date; schedule: Schedule; } type SchedulerState = ReadonlyArray; +const executeAll = ( + jobs: ReadonlyArray>, +): T.Task, ReadonlyArray>> => + pipe(jobs, RA.wilt(T.ApplicativePar)(identity)); + export const schedulerLoop = (state: SchedulerState): TE.TaskEither => () => { - const loop = (currentState: SchedulerState): TE.TaskEither => + const loop = ( + currentState: SchedulerState, + time: Date, + ): TE.TaskEither => pipe( - executeDueJobs(currentState), - delay(1000), // Delay for 1 second - map((newState) => loop(newState)), + currentState, + RA.filter((job) => job.at <= time), + RA.map(({ execute }) => execute()), + executeAll, + //T.delay(1000), // Delay for 1 second + // map((newState) => loop(newState)), ); return loop(state)(); -- cgit v1.3