aboutsummaryrefslogtreecommitdiff
path: root/src/util/scheduler.ts
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-07-02 11:10:07 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2026-07-02 11:10:07 -0700
commit2859955095020b07909b079d34be8a80e7f58ecd (patch)
treeb10ee799208a50a800fe5cee47ade46c90770d2e /src/util/scheduler.ts
parent5dbd16878546886cae5b56b67de6185bfbae0d07 (diff)
downloadmon.hatecomputers.club-2859955095020b07909b079d34be8a80e7f58ecd.tar.gz
mon.hatecomputers.club-2859955095020b07909b079d34be8a80e7f58ecd.zip
BackupHEADmain
Diffstat (limited to 'src/util/scheduler.ts')
-rw-r--r--src/util/scheduler.ts28
1 files changed, 21 insertions, 7 deletions
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)();