diff options
| author | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-07-02 11:10:07 -0700 |
|---|---|---|
| committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-07-02 11:10:07 -0700 |
| commit | 2859955095020b07909b079d34be8a80e7f58ecd (patch) | |
| tree | b10ee799208a50a800fe5cee47ade46c90770d2e /src | |
| parent | 5dbd16878546886cae5b56b67de6185bfbae0d07 (diff) | |
| download | mon.hatecomputers.club-main.tar.gz mon.hatecomputers.club-main.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/canary/job.ts | 18 | ||||
| -rw-r--r-- | src/publisher/index.ts | 23 | ||||
| -rw-r--r-- | src/util/scheduler.ts | 28 |
3 files changed, 22 insertions, 47 deletions
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<Error, boolean>; + execute: () => TE.TaskEither<Error, boolean>; at: Date; schedule: Schedule; } type SchedulerState = ReadonlyArray<ScheduledJob>; +const executeAll = ( + jobs: ReadonlyArray<TE.TaskEither<Error, boolean>>, +): T.Task<Separated<ReadonlyArray<Error>, ReadonlyArray<boolean>>> => + pipe(jobs, RA.wilt(T.ApplicativePar)(identity)); + export const schedulerLoop = (state: SchedulerState): TE.TaskEither<Error, void> => () => { - const loop = (currentState: SchedulerState): TE.TaskEither<Error, void> => + const loop = ( + currentState: SchedulerState, + time: Date, + ): TE.TaskEither<Error, void> => 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)(); |
