aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/job.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-05-02 22:02:27 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-05-04 21:12:32 +0200
commit227d02feadbc9b1fc916a12528ccc0623fb3069e (patch)
tree0b6bcc8c2c081591588714bc040ac6e810e333de /server/models/job.js
parent15d4ee04a94230e1ea83c2959a1981105699ba22 (diff)
downloadPeerTube-227d02feadbc9b1fc916a12528ccc0623fb3069e.tar.gz
PeerTube-227d02feadbc9b1fc916a12528ccc0623fb3069e.tar.zst
PeerTube-227d02feadbc9b1fc916a12528ccc0623fb3069e.zip
Server: add job scheduler to transcode video files
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}