diff options
author | eug-vs <eug-vs@keemail.me> | 2020-12-02 00:29:25 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-12-02 00:29:25 +0300 |
commit | 972e0578f999aadb5924d84768e59445c92f167b (patch) | |
tree | 7ec9a8c09f33b8a6f2aa0b3db5fb93889f410a29 /lib/schema.ts | |
parent | fc3701733fca3fccd8330aaa5095fdcd82daf2b7 (diff) | |
download | mongo-cronjob-972e0578f999aadb5924d84768e59445c92f167b.tar.gz |
feat: add schema and model
Diffstat (limited to 'lib/schema.ts')
-rw-r--r-- | lib/schema.ts | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/schema.ts b/lib/schema.ts new file mode 100644 index 0000000..4e5dd69 --- /dev/null +++ b/lib/schema.ts @@ -0,0 +1,35 @@ +import { Schema, Document } from 'mongoose'; + +export interface EventDocument<Context> extends Document { + name: string; + schedule: string; + status: 'notStarted' | 'running' | 'complete' | 'failed'; + error?: string; + context: Context; + nextRunAt: Date; + lastRunAt: Date; +} + +const createEventSchema = (contextSchema: Schema) => new Schema({ + name: { + type: String, + required: true, + unique: true + }, + schedule: { + type: String, + required: true + }, + status: { + type: String, + default: 'notStarted' + }, + error: String, + context: contextSchema, + nextRunAt: Date, + lastRunAt: Date +}, { timestamps: true }); + + +export default createEventSchema; + |