69 lines
1.5 KiB
JavaScript
69 lines
1.5 KiB
JavaScript
// node_api/models/JobStatus.js
|
|
const { DataTypes } = require('sequelize');
|
|
const { sequelize } = require('../config/database');
|
|
|
|
const JobStatus = sequelize.define('JobStatus', {
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true
|
|
},
|
|
job_name: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
comment: 'Name of the scheduled job'
|
|
},
|
|
execution_id: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
unique: true,
|
|
comment: 'Unique identifier for this job execution'
|
|
},
|
|
status: {
|
|
type: DataTypes.ENUM('running', 'completed', 'failed'),
|
|
allowNull: false,
|
|
defaultValue: 'running'
|
|
},
|
|
started_at: {
|
|
type: DataTypes.DATE,
|
|
allowNull: false,
|
|
defaultValue: DataTypes.NOW
|
|
},
|
|
completed_at: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true
|
|
},
|
|
duration_ms: {
|
|
type: DataTypes.INTEGER,
|
|
allowNull: true,
|
|
comment: 'Job execution duration in milliseconds'
|
|
},
|
|
error_message: {
|
|
type: DataTypes.TEXT,
|
|
allowNull: true,
|
|
comment: 'Error message if job failed'
|
|
},
|
|
details: {
|
|
type: DataTypes.JSONB,
|
|
allowNull: true,
|
|
comment: 'Additional details about job execution (success data, error details, etc.)'
|
|
}
|
|
}, {
|
|
tableName: 'job_status',
|
|
timestamps: true,
|
|
createdAt: 'created_at',
|
|
updatedAt: 'updated_at',
|
|
indexes: [
|
|
{
|
|
fields: ['job_name', 'started_at']
|
|
},
|
|
{
|
|
fields: ['status']
|
|
},
|
|
{
|
|
fields: ['execution_id']
|
|
}
|
|
]
|
|
});
|
|
|
|
module.exports = { JobStatus }; |