aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.ts12
-rw-r--r--src/args.ts9
-rw-r--r--src/canary/email.ts2
-rw-r--r--src/config.ts9
-rw-r--r--src/index.ts6
-rw-r--r--src/publisher/index.ts8
-rw-r--r--src/util/index.ts1
-rw-r--r--src/util/scheduler.ts25
-rw-r--r--tst/canary/email.spec.ts2
9 files changed, 54 insertions, 20 deletions
diff --git a/index.ts b/index.ts
deleted file mode 100644
index 4c181c3..0000000
--- a/index.ts
+++ /dev/null
@@ -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>());
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<Config> =>
+ () => {
+ 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<void> = 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<boolean, Error>): 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<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)();
+ };
diff --git a/tst/canary/email.spec.ts b/tst/canary/email.spec.ts
index fa22e37..375816f 100644
--- a/tst/canary/email.spec.ts
+++ b/tst/canary/email.spec.ts
@@ -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 { perform, type EmailJobDependencies } from "../../src/canary/email";
import type {