]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/models/job.js
Server: add job scheduler to transcode video files
[github/Chocobozzz/PeerTube.git] / server / models / job.js
1 'use strict'
2
3 const values = require('lodash/values')
4
5 const constants = require('../initializers/constants')
6
7 // ---------------------------------------------------------------------------
8
9 module.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
42 function 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 }