aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-12-02 00:56:13 +0300
committereug-vs <eug-vs@keemail.me>2020-12-02 01:07:12 +0300
commit6044d7d68c8f8974a715a6ab3b4efe9eb2a65fdf (patch)
treeed165b5cc51a1d8707aa745efb92c9326c265d0b
parent01a5216fa10b15b5b159e31bbc692ef8a4460f03 (diff)
downloadmongo-cronjob-6044d7d68c8f8974a715a6ab3b4efe9eb2a65fdf.tar.gz
feat: add model interface
-rw-r--r--lib/model.ts11
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/model.ts b/lib/model.ts
index 77fede0..218b8ef 100644
--- a/lib/model.ts
+++ b/lib/model.ts
@@ -6,13 +6,18 @@ interface Event<Context> extends EventDocument<Context> {
log(message: string): void;
start(): void;
complete(): void;
- fail(): void;
+ fail(error: Error): void;
computeNextRunAt(): Date;
}
+export interface EventModel<Context> extends Model<Event<Context>> {
+ findNextEvents(): Event<Context>[];
+ findMissedEvents(): Event<Context>[];
+}
+
const CronJob = cron.CronJob;
-const createEventModel = <Context extends Schema>(name: string, contextSchema: Context) => {
+const createEventModel = <Context extends Schema>(name: string, contextSchema: Context): EventModel<Context> => {
const schema = createEventSchema(contextSchema);
// Schema methods
@@ -79,7 +84,7 @@ const createEventModel = <Context extends Schema>(name: string, contextSchema: C
this.nextRunAt = this.computeNextRunAt();
});
- return model<Event<Context>>(name, schema);
+ return model<Event<Context>, EventModel<Context>>(name, schema);
};