Skip to content

Commit

Permalink
feat(pipeline): add model pipelineStep
Browse files Browse the repository at this point in the history
  • Loading branch information
germainvictor committed May 25, 2021
1 parent 454647c commit 3460423
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/gnj.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ commander_1["default"]
models = models_1["default"](config);
return [4 /*yield*/, migrate_1["default"](models)];
case 1:
_a.sent();
return [4 /*yield*/, models.sequelize.close()];
case 2:
_a.sent();
return [2 /*return*/];
}
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/getApolloServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var models_1 = __importDefault(require("../models"));
var job_1 = __importDefault(require("./job"));
var batch_1 = __importDefault(require("./batch"));
var pipeline_1 = __importDefault(require("./pipeline"));
var pipelineStep_1 = __importDefault(require("./pipelineStep"));
var jobHoldType_1 = __importDefault(require("./jobHoldType"));
/**
* @param dbConfig Sequelize database configuration object
Expand All @@ -33,6 +34,7 @@ function getApolloServer(dbConfig, gsgParams, customMutations) {
job: job_1["default"](types, models),
batch: batch_1["default"](types, models),
pipeline: pipeline_1["default"](types, models),
pipelineStep: pipelineStep_1["default"](types, models),
jobHoldType: jobHoldType_1["default"](types, models)
};
return graphql_sequelize_generator_1.generateApolloServer(__assign({ graphqlSchemaDeclaration: graphqlSchemaDeclaration,
Expand Down
8 changes: 4 additions & 4 deletions lib/graphql/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ var CancelRequestedError = /** @class */ (function (_super) {
exports.CancelRequestedError = CancelRequestedError;
var allInstanceOfDebounceBatch = [];
function getInstanceOfDebounceBatch(batchId) {
var instanceAlreadyExist = allInstanceOfDebounceBatch.filter(function (instance) { return instance.batchId === batchId; });
if (!instanceAlreadyExist.length) {
var instance = allInstanceOfDebounceBatch.filter(function (instance) { return instance.batchId === batchId; });
if (!instance.length) {
allInstanceOfDebounceBatch.push({
batchId: batchId,
debounce: debounce_1["default"](function (callback) { return callback(); }, 50)
});
return allInstanceOfDebounceBatch.filter(function (instance) { return instance.batchId === batchId; })[0].debounce;
}
return instanceAlreadyExist[0].debounce;
return instance[0].debounce;
}
function JobConfiguration(graphqlTypes, models) {
var _this = this;
Expand Down Expand Up @@ -192,7 +192,7 @@ function JobConfiguration(graphqlTypes, models) {
}); }
},
create: {
preventDuplicateOnAttributes: ['jobUniqueId']
// preventDuplicateOnAttributes: ['jobUniqueId'],
}
};
}
Expand Down
14 changes: 14 additions & 0 deletions lib/graphql/pipelineStep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";
exports.__esModule = true;
function PipelineStepConfiguration(types, models) {
return {
model: models.pipelineStep,
actions: ['list', 'update', 'create', 'count'],
list: {
before: function (findOptions) {
return findOptions;
}
}
};
}
exports["default"] = PipelineStepConfiguration;
8 changes: 8 additions & 0 deletions lib/models/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ function Pipeline(sequelize) {
primaryKey: true,
autoIncrement: true
},
status: {
type: sequelize_1.DataTypes.STRING,
allowNull: false,
defaultValue: 'planned',
validate: {
isIn: [['planned', 'processing', 'failed', 'successful']]
}
},
name: {
type: sequelize_1.DataTypes.STRING
},
Expand Down
37 changes: 37 additions & 0 deletions lib/models/pipelineStep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use strict";
exports.__esModule = true;
var sequelize_1 = require("sequelize");
function PipelineStep(sequelize) {
var PipelineStep = sequelize.define('pipelineStep', {
id: {
type: sequelize_1.DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
jobId: {
type: sequelize_1.DataTypes.INTEGER
},
batchId: {
type: sequelize_1.DataTypes.INTEGER
},
index: {
type: sequelize_1.DataTypes.INTEGER
}
}, {
freezeTableName: true,
tableName: 'pipelineStep',
paranoid: true
});
PipelineStep.associate = function (models) {
models.job.belongsTo(models.job, {
foreignKey: 'jobId',
sourceKey: 'id'
});
models.job.belongsTo(models.batch, {
foreignKey: 'batchId',
sourceKey: 'id'
});
};
return PipelineStep;
}
exports["default"] = PipelineStep;
25 changes: 25 additions & 0 deletions migrations/20201130230919-create-pipelineStep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict'
module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.createTable('pipelineStep', {
id: {
allowNull: false,
autoIncrement: true,
primaryKey: true,
type: Sequelize.INTEGER,
},
jobId: {
type: Sequelize.INTEGER,
},
batchId: {
type: Sequelize.INTEGER,
},
index: {
type: Sequelize.INTEGER,
},
})
},
down: function (queryInterface) {
return queryInterface.dropTable('pipelineStep')
},
}
2 changes: 2 additions & 0 deletions src/graphql/getApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import getModels from '../models'
import job from './job'
import batch from './batch'
import pipeline from './pipeline'
import pipelineStep from './pipelineStep'
import jobHoldType from './jobHoldType'

/**
Expand All @@ -26,6 +27,7 @@ export default function getApolloServer(
job: job(types, models),
batch: batch(types, models),
pipeline: pipeline(types, models),
pipelineStep: pipelineStep(types, models),
jobHoldType: jobHoldType(types, models),
}

Expand Down
2 changes: 1 addition & 1 deletion src/graphql/job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default function JobConfiguration(
},
},
create: {
preventDuplicateOnAttributes: ['jobUniqueId'],
// preventDuplicateOnAttributes: ['jobUniqueId'],
},
}
}
20 changes: 20 additions & 0 deletions src/graphql/pipelineStep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
InAndOutTypes,
ModelDeclarationType,
SequelizeModels,
} from 'graphql-sequelize-generator/types'

export default function PipelineStepConfiguration(
types: InAndOutTypes,
models: SequelizeModels
): ModelDeclarationType {
return {
model: models.pipelineStep,
actions: ['list', 'update', 'create', 'count'],
list: {
before: (findOptions) => {
return findOptions
},
},
}
}
39 changes: 39 additions & 0 deletions src/models/pipelineStep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { DataTypes } from 'sequelize'

export default function PipelineStep(sequelize: any) {
var PipelineStep = sequelize.define(
'pipelineStep',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
jobId: {
type: DataTypes.INTEGER,
},
batchId: {
type: DataTypes.INTEGER,
},
index: {
type: DataTypes.INTEGER,
},
},
{
freezeTableName: true,
tableName: 'pipelineStep',
paranoid: true,
}
)
PipelineStep.associate = function (models: any) {
models.job.belongsTo(models.job, {
foreignKey: 'jobId',
sourceKey: 'id',
})
models.job.belongsTo(models.batch, {
foreignKey: 'batchId',
sourceKey: 'id',
})
}
return PipelineStep
}

0 comments on commit 3460423

Please sign in to comment.