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