aboutsummaryrefslogtreecommitdiff
path: root/lib/event.schema.ts
blob: 0f428fd7e93e52cbf67813333001eaa56e3c8530 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Schema, Document } from 'mongoose';

export interface EventDocument<Context> extends Document {
  type: string;
  schedule: string;
  status: 'notStarted' | 'running' | 'complete' | 'failed';
  error?: string;
  context: Context;
  nextRunAt?: Date;
  lastRunAt?: Date;
}

const createEventSchema = (contextSchema: Schema) => new Schema({
  type: {
    type: String,
    required: true
  },
  schedule: {
    type: String,
    required: true
  },
  status: {
    type: String,
    default: 'notStarted'
  },
  error: String,
  context: contextSchema,
  nextRunAt: Date,
  lastRunAt: Date
}, { timestamps: true });


export default createEventSchema;