UNPKG

@use-services/cron

Version:

```ts import * as Cron from "@use-services/cron"; import * as handlersCron from "@/handlersCron";

34 lines (33 loc) 979 B
import { ServiceOption, InitOption, STOP_KEY } from "use-services"; import { Service as IORedisService } from "@use-services/ioredis"; export declare type Option<A, S extends Service<A>> = ServiceOption<Args<A>, S>; export interface Args<A> { pollInterval?: number; crons: { [k in keyof A]: string; }; handlers: A; } export declare type Deps = [IORedisService]; export declare class Service<A> { private args; private redis; private initialized; private ns; private timer; constructor(option: InitOption<Args<A>, Service<A>>); start(): Promise<void>; [STOP_KEY](): Promise<void>; private _addInterval; private _runinterval; private _redisKey; private _getSchedules; private _checkHandlers; } export declare function init<A, S extends Service<A>>(option: InitOption<Args<A>, S>): Promise<S>; export declare type Context = { name: string; cron: string; nextRunAt: Date; runAts: Date[]; };