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