X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fjob%2Fjob.ts;h=c2d088090accc4068bce6d45694a69b10190a8ff;hb=1f3e9feca2caf68024168b0ea9ed39d8438fa235;hp=968f9d71ddcba2b85bcc818d8d9bc5befcca5cb2;hpb=6fcd19ba737f1f5614a56c6925adb882dea43b8d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/job/job.ts b/server/models/job/job.ts index 968f9d71d..c2d088090 100644 --- a/server/models/job/job.ts +++ b/server/models/job/job.ts @@ -1,7 +1,7 @@ import { values } from 'lodash' import * as Sequelize from 'sequelize' -import { JOB_STATES } from '../../initializers' +import { JOB_STATES, JOB_CATEGORIES } from '../../initializers' import { addMethodsToModel } from '../utils' import { @@ -10,10 +10,10 @@ import { JobMethods } from './job-interface' -import { JobState } from '../../../shared/models/job.model' +import { JobCategory, JobState } from '../../../shared/models/job.model' let Job: Sequelize.Model -let listWithLimit: JobMethods.ListWithLimit +let listWithLimitByCategory: JobMethods.ListWithLimitByCategory export default function defineJob (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.DataTypes) { Job = sequelize.define('Job', @@ -22,6 +22,10 @@ export default function defineJob (sequelize: Sequelize.Sequelize, DataTypes: Se type: DataTypes.ENUM(values(JOB_STATES)), allowNull: false }, + category: { + type: DataTypes.ENUM(values(JOB_CATEGORIES)), + allowNull: false + }, handlerName: { type: DataTypes.STRING, allowNull: false @@ -34,13 +38,13 @@ export default function defineJob (sequelize: Sequelize.Sequelize, DataTypes: Se { indexes: [ { - fields: [ 'state' ] + fields: [ 'state', 'category' ] } ] } ) - const classMethods = [ listWithLimit ] + const classMethods = [ listWithLimitByCategory ] addMethodsToModel(Job, classMethods) return Job @@ -48,14 +52,15 @@ export default function defineJob (sequelize: Sequelize.Sequelize, DataTypes: Se // --------------------------------------------------------------------------- -listWithLimit = function (limit: number, state: JobState) { +listWithLimitByCategory = function (limit: number, state: JobState, jobCategory: JobCategory) { const query = { order: [ [ 'id', 'ASC' ] ], limit: limit, where: { - state + state, + category: jobCategory } }