]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/job.ts
First typescript iteration
[github/Chocobozzz/PeerTube.git] / server / models / job.ts
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 }