feat: ghetto durable compute

This commit is contained in:
Mythie
2024-05-16 15:44:39 +10:00
parent 61827ad729
commit 991f808890
20 changed files with 847 additions and 151 deletions

View File

@ -1,16 +1,20 @@
import { z } from 'zod';
import type { Json } from './json';
export const ZTriggerJobOptionsSchema = z.object({
id: z.string().optional(),
name: z.string(),
payload: z.unknown().refine((x) => x !== undefined, { message: 'payload is required' }),
payload: z.any().refine((x) => x !== undefined, { message: 'payload is required' }),
timestamp: z.number().optional(),
});
// The Omit is a temporary workaround for a "bug" in the zod library
// @see: https://github.com/colinhacks/zod/issues/2966
export type TriggerJobOptions = Omit<z.infer<typeof ZTriggerJobOptionsSchema>, 'payload'> & {
payload: unknown;
// Don't tell the feds
// eslint-disable-next-line @typescript-eslint/no-explicit-any
payload: any;
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@ -28,7 +32,7 @@ export type JobDefinition<T = any> = {
export interface JobRunIO {
// stableRun<T extends Json | void>(cacheKey: string, callback: (io: JobRunIO) => T | Promise<T>): Promise<T>;
stableRun<T extends Json | void>(cacheKey: string, callback: () => Promise<T>): Promise<T>;
runTask<T extends Json | void>(cacheKey: string, callback: () => Promise<T>): Promise<T>;
triggerJob(cacheKey: string, options: TriggerJobOptions): Promise<unknown>;
wait(cacheKey: string, ms: number): Promise<void>;
logger: {