Skip to content

Commit

Permalink
Houfeng#13 hotfix to resolve SN for automation
Browse files Browse the repository at this point in the history
  • Loading branch information
hailiang-wang committed Dec 8, 2017
1 parent 2a2818d commit ee3948c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
22 changes: 22 additions & 0 deletions lib/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,28 @@ const Store = new Class({
});
},

/**
* 计算下一个 Record执行的sn
*/
resolveNextRecordSN: function(job, callback){
var self = this;
callback = callback || utils.NOOP;
return self.Record.find({
projectName: job.project ? job.project.name : job.projectName,
name: job.name
}, { offset: 0 }, 1,
['sn', 'Z'], function (err, records) {
if (err) return callback(err);
if (job.refused) {
// refused 的 Job 的 sn 固定为 0;
job.sn = 0;
} else {
job.sn = records && records[0] ? records[0].sn + 1 : 1;
}
callback(null, job.sn);
});
},

/**
* 插入 job 执行记录
* @param {Job} job job 实例
Expand Down
32 changes: 19 additions & 13 deletions web/controllers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,25 @@ const ApiController = nokit.define({
**/
trigger: function (context, params) {
var self = this;
self.server.ci.externalInvoke(
self.projectName,
self.jobName,
{
params: params || self.params
},
null,
function (started) {
self.send(started ? 202 : 400, {
message: started ? 'Job is triggered' : 'Trigger failed'
});
}
);
self.server.ci.store.resolveNextRecordSN({
projectName: self.projectName,
name: self.jobName,
refused: false
}, function(err, sn) {
self.server.ci.externalInvoke(
self.projectName,
self.jobName, {
params: params || self.params
},
null,
function(started) {
self.send(started ? 202 : 400, {
message: started ? 'Job is triggered' : 'Trigger failed',
sn: sn
});
}
);
});
},

/**
Expand Down

0 comments on commit ee3948c

Please sign in to comment.