PeerTube/server/models/job.ts

53 lines
992 B
TypeScript
Raw Normal View History

2017-05-15 15:22:03 -05:00
import { values } from 'lodash'
2017-05-15 15:22:03 -05:00
import { JOB_STATES } from '../initializers'
// ---------------------------------------------------------------------------
module.exports = function (sequelize, DataTypes) {
const Job = sequelize.define('Job',
{
state: {
2017-05-15 15:22:03 -05:00
type: DataTypes.ENUM(values(JOB_STATES)),
allowNull: false
},
handlerName: {
type: DataTypes.STRING,
allowNull: false
},
handlerInputData: {
type: DataTypes.JSON,
allowNull: true
}
},
{
indexes: [
{
fields: [ 'state' ]
}
],
classMethods: {
listWithLimit
}
}
)
return Job
}
// ---------------------------------------------------------------------------
2017-05-05 10:24:16 -05:00
function listWithLimit (limit, state, callback) {
const query = {
order: [
[ 'id', 'ASC' ]
],
limit: limit,
where: {
2017-05-05 10:24:16 -05:00
state
}
}
return this.findAll(query).asCallback(callback)
}