From ad74ff999589e0df2b60ba6e94362ed5215af312 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 28 Jul 2024 14:10:38 -0700 Subject: something --- src/args.ts | 9 +++++++++ src/canary/email.ts | 2 +- src/config.ts | 9 +++++++++ src/index.ts | 6 ++++++ src/publisher/index.ts | 8 ++------ src/util/index.ts | 1 + src/util/scheduler.ts | 25 +++++++++++++++++++++++++ 7 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 src/args.ts create mode 100644 src/util/scheduler.ts (limited to 'src') diff --git a/src/args.ts b/src/args.ts new file mode 100644 index 0000000..31fa2ee --- /dev/null +++ b/src/args.ts @@ -0,0 +1,9 @@ +export interface Args { + testFile: string; +} + +export const parseArgs = (argv: string[]): Args => { + const useful = argv.slice(2); // skip bun path and script path + + const flags = useful.map((x, i) => x.startsWith("--") && i); +}; diff --git a/src/canary/email.ts b/src/canary/email.ts index 384212b..1961c60 100644 --- a/src/canary/email.ts +++ b/src/canary/email.ts @@ -12,7 +12,7 @@ import { } from "imapflow"; import * as IO from "fp-ts/lib/IO"; import * as T from "fp-ts/lib/Task"; -import { ConsoleLogger } from "../util/logger"; +import { ConsoleLogger } from "../util"; interface ImapClientI { fetchAll: ( diff --git a/src/config.ts b/src/config.ts index dd96169..2da569f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,7 +1,16 @@ +import * as IO from "fp-ts/IO"; import type { Publisher } from "./publisher"; +import { readFileSync } from "fs"; export interface Config { result_publishers: Publisher[]; dns: string[]; timeout: string; } + +export const readConfig = + (filePath: string): IO.IO => + () => { + const confStr = readFileSync(filePath, "utf-8"); + return JSON.parse(confStr); + }; diff --git a/src/index.ts b/src/index.ts index e69de29..95fd41f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -0,0 +1,6 @@ +import * as IO from "fp-ts/IO"; +import { readFileSync } from "fs"; + +const main: IO.IO = ConsoleLogger.log("Hello, world!"); + +main(); diff --git a/src/publisher/index.ts b/src/publisher/index.ts index e721160..f37e108 100644 --- a/src/publisher/index.ts +++ b/src/publisher/index.ts @@ -1,4 +1,4 @@ -import type { Duration, Result } from "../util"; +import { D } from "../util"; export enum PublisherType { DISCORD = "discord", @@ -18,10 +18,6 @@ export type PublisherPost = DiscordPost | NtfyPost; export interface Publisher { type: PublisherType; - at: Duration; + at: D.Duration; post: PublisherPost; } - -export interface ResultPublishable { - publish(testResult: Result): void; -} diff --git a/src/util/index.ts b/src/util/index.ts index acf8771..dd356fb 100644 --- a/src/util/index.ts +++ b/src/util/index.ts @@ -1 +1,2 @@ export * as D from "./duration"; +export * from "./logger"; diff --git a/src/util/scheduler.ts b/src/util/scheduler.ts new file mode 100644 index 0000000..9f9f594 --- /dev/null +++ b/src/util/scheduler.ts @@ -0,0 +1,25 @@ +import * as TE from "fp-ts/lib/TaskEither"; +import { pipe } from "fp-ts/lib/function"; +import type { Schedule } from "../canary"; + +interface ScheduledJob { + id: string; + execute: TE.TaskEither; + at: Date; + schedule: Schedule; +} + +type SchedulerState = ReadonlyArray; + +export const schedulerLoop = + (state: SchedulerState): TE.TaskEither => + () => { + const loop = (currentState: SchedulerState): TE.TaskEither => + pipe( + executeDueJobs(currentState), + delay(1000), // Delay for 1 second + map((newState) => loop(newState)), + ); + + return loop(state)(); + }; -- cgit v1.3