diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-05-15 22:22:03 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-05-20 09:57:40 +0200 |
commit | 65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch) | |
tree | 4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/models/job.ts | |
parent | d5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff) | |
download | PeerTube-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.ts | 52 |
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 @@ | |||
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 | } | ||