aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/job.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-05-15 22:22:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-05-20 09:57:40 +0200
commit65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch)
tree4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/models/job.ts
parentd5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff)
downloadPeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip
First typescript iteration
Diffstat (limited to 'server/models/job.ts')
-rw-r--r--server/models/job.ts52
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 @@
1import { values } from 'lodash'
2
3import { JOB_STATES } from '../initializers'
4
5// ---------------------------------------------------------------------------
6
7module.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
40function 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}