diff options
Diffstat (limited to 'server/models/job.ts')
-rw-r--r-- | server/models/job.ts | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/server/models/job.ts b/server/models/job.ts new file mode 100644 index 000000000..6843e399b --- /dev/null +++ b/server/models/job.ts | |||
@@ -0,0 +1,52 @@ | |||
1 | import { values } from 'lodash' | ||
2 | |||
3 | import { JOB_STATES } from '../initializers' | ||
4 | |||
5 | // --------------------------------------------------------------------------- | ||
6 | |||
7 | module.exports = function (sequelize, DataTypes) { | ||
8 | const Job = sequelize.define('Job', | ||
9 | { | ||
10 | state: { | ||
11 | type: DataTypes.ENUM(values(JOB_STATES)), | ||
12 | allowNull: false | ||
13 | }, | ||
14 | handlerName: { | ||
15 | type: DataTypes.STRING, | ||
16 | allowNull: false | ||
17 | }, | ||
18 | handlerInputData: { | ||
19 | type: DataTypes.JSON, | ||
20 | allowNull: true | ||
21 | } | ||
22 | }, | ||
23 | { | ||
24 | indexes: [ | ||
25 | { | ||
26 | fields: [ 'state' ] | ||
27 | } | ||
28 | ], | ||
29 | classMethods: { | ||
30 | listWithLimit | ||
31 | } | ||
32 | } | ||
33 | ) | ||
34 | |||
35 | return Job | ||
36 | } | ||
37 | |||
38 | // --------------------------------------------------------------------------- | ||
39 | |||
40 | function listWithLimit (limit, state, callback) { | ||
41 | const query = { | ||
42 | order: [ | ||
43 | [ 'id', 'ASC' ] | ||
44 | ], | ||
45 | limit: limit, | ||
46 | where: { | ||
47 | state | ||
48 | } | ||
49 | } | ||
50 | |||
51 | return this.findAll(query).asCallback(callback) | ||
52 | } | ||