Files
parcer/server/src/models/Run.ts

112 lines
2.4 KiB
TypeScript
Raw Normal View History

2024-10-09 03:27:04 +05:30
import { Model, DataTypes, Optional } from 'sequelize';
import sequelize from '../db/config';
import Robot from './Robot';
2024-10-09 15:45:22 +05:30
// TODO:
// 1. rename variables
// 2. we might not need interpreter settings?
// 3. store binaryOutput in MinIO
2024-10-09 14:43:48 +05:30
interface InterpreterSettings {
maxConcurrency: number;
maxRepeats: number;
debug: boolean;
}
2024-10-09 03:27:04 +05:30
interface RunAttributes {
2024-10-09 14:43:48 +05:30
id: string;
status: string;
name: string;
robotId: string;
startedAt: string;
finishedAt: string;
browserId: string;
interpreterSettings: InterpreterSettings;
log: string;
runId: string;
serializableOutput: Record<string, any[]>;
binaryOutput: Record<string, any>;
2024-10-09 03:27:04 +05:30
}
2024-10-09 03:27:19 +05:30
interface RunCreationAttributes extends Optional<RunAttributes, 'id'> { }
2024-10-09 03:27:04 +05:30
class Run extends Model<RunAttributes, RunCreationAttributes> implements RunAttributes {
2024-10-09 14:43:48 +05:30
public id!: string;
public status!: string;
public name!: string;
public robotId!: string;
public startedAt!: string;
public finishedAt!: string;
public browserId!: string;
public interpreterSettings!: InterpreterSettings;
public log!: string;
public runId!: string;
public serializableOutput!: Record<string, any[]>;
public binaryOutput!: Record<string, any>;
2024-10-09 03:27:04 +05:30
}
Run.init(
2024-10-09 14:43:48 +05:30
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
status: {
type: DataTypes.STRING(50),
allowNull: false,
},
name: {
type: DataTypes.STRING(255),
allowNull: false,
},
robotId: {
type: DataTypes.UUID,
allowNull: false,
references: {
model: Robot,
key: 'id',
},
},
startedAt: {
type: DataTypes.STRING(255),
allowNull: false,
},
finishedAt: {
type: DataTypes.STRING(255),
allowNull: false,
},
browserId: {
type: DataTypes.UUID,
allowNull: false,
},
interpreterSettings: {
type: DataTypes.JSONB,
allowNull: false,
},
log: {
type: DataTypes.TEXT,
allowNull: true,
},
runId: {
type: DataTypes.UUID,
allowNull: false,
},
serializableOutput: {
type: DataTypes.JSONB,
allowNull: true,
},
binaryOutput: {
type: DataTypes.JSONB,
allowNull: true,
2024-10-09 03:27:04 +05:30
},
2024-10-09 14:43:48 +05:30
},
{
sequelize,
tableName: 'run',
timestamps: false,
}
2024-10-09 03:27:04 +05:30
);
Run.belongsTo(Robot, { foreignKey: 'robotId' });
2024-10-09 14:43:48 +05:30
export default Run;