something

This commit is contained in:
Elizabeth Hunt 2024-07-28 14:10:38 -07:00
parent 452c41a75a
commit ad74ff9995
Signed by untrusted user who does not match committer: simponic
GPG Key ID: 2909B9A7FF6213EE
9 changed files with 54 additions and 20 deletions

View File

@ -1,12 +0,0 @@
import * as S from "fp-ts/String";
import * as M from "fp-ts/Map";
import { getMonoid } from "fp-ts/lib/Array";
enum DurationUnit {
MILLISECOND = "ms",
SECOND = "sec",
MINUTE = "min",
HOUR = "hr",
}
const unitMap = M.fromFoldable(S.Ord, getMonoid<String>());

9
src/args.ts Normal file
View File

@ -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);
};

View File

@ -12,7 +12,7 @@ import {
} from "imapflow"; } from "imapflow";
import * as IO from "fp-ts/lib/IO"; import * as IO from "fp-ts/lib/IO";
import * as T from "fp-ts/lib/Task"; import * as T from "fp-ts/lib/Task";
import { ConsoleLogger } from "../util/logger"; import { ConsoleLogger } from "../util";
interface ImapClientI { interface ImapClientI {
fetchAll: ( fetchAll: (

View File

@ -1,7 +1,16 @@
import * as IO from "fp-ts/IO";
import type { Publisher } from "./publisher"; import type { Publisher } from "./publisher";
import { readFileSync } from "fs";
export interface Config { export interface Config {
result_publishers: Publisher[]; result_publishers: Publisher[];
dns: string[]; dns: string[];
timeout: string; timeout: string;
} }
export const readConfig =
(filePath: string): IO.IO<Config> =>
() => {
const confStr = readFileSync(filePath, "utf-8");
return JSON.parse(confStr);
};

View File

@ -0,0 +1,6 @@
import * as IO from "fp-ts/IO";
import { readFileSync } from "fs";
const main: IO.IO<void> = ConsoleLogger.log("Hello, world!");
main();

View File

@ -1,4 +1,4 @@
import type { Duration, Result } from "../util"; import { D } from "../util";
export enum PublisherType { export enum PublisherType {
DISCORD = "discord", DISCORD = "discord",
@ -18,10 +18,6 @@ export type PublisherPost = DiscordPost | NtfyPost;
export interface Publisher { export interface Publisher {
type: PublisherType; type: PublisherType;
at: Duration; at: D.Duration;
post: PublisherPost; post: PublisherPost;
} }
export interface ResultPublishable {
publish(testResult: Result<boolean, Error>): void;
}

View File

@ -1 +1,2 @@
export * as D from "./duration"; export * as D from "./duration";
export * from "./logger";

25
src/util/scheduler.ts Normal file
View File

@ -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<Error, boolean>;
at: Date;
schedule: Schedule;
}
type SchedulerState = ReadonlyArray<ScheduledJob>;
export const schedulerLoop =
(state: SchedulerState): TE.TaskEither<Error, void> =>
() => {
const loop = (currentState: SchedulerState): TE.TaskEither<Error, void> =>
pipe(
executeDueJobs(currentState),
delay(1000), // Delay for 1 second
map((newState) => loop(newState)),
);
return loop(state)();
};

View File

@ -1,4 +1,4 @@
import { mock, test, expect, beforeEach } from "bun:test"; import { mock, test, expect } from "bun:test";
import * as TE from "fp-ts/lib/TaskEither"; import * as TE from "fp-ts/lib/TaskEither";
import { perform, type EmailJobDependencies } from "../../src/canary/email"; import { perform, type EmailJobDependencies } from "../../src/canary/email";
import type { import type {