Skip to content

Commit

Permalink
Update attributes on cancel job. Fixes #617 (#619)
Browse files Browse the repository at this point in the history
WIP #617 moved client edits out of promise

WIP #617 Made 'isRunning' more robust

WIP #617 Fixed client calls
  • Loading branch information
brollb authored Aug 4, 2016
1 parent e2980d6 commit a7e08aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/visualizers/panels/ForgeActionButton/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,16 @@ define([
action: function() {
// Stop every running job
var execNode = this.client.getNode(this._currentNodeId),
jobIds = execNode.getChildrenIds();
jobIds = execNode.getChildrenIds(),
msg = `Canceling ${execNode.getAttribute('name')} execution`;

this.client.startTransaction(msg);
jobIds.map(id => this.client.getNode(id))
.filter(job => this.isJobRunning(job)) // get running jobs
.filter(job => this.isRunning(job)) // get running jobs
.forEach(job => this.stopJob(job)); // stop them

this.client.setAttributes(execNode.getId(), 'status', 'canceled');
this.client.completeTransaction();
}
}
],
Expand Down
28 changes: 20 additions & 8 deletions src/visualizers/panels/ForgeActionButton/ForgeActionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,20 +351,25 @@ define([
});
};

ForgeActionButton.prototype.isRunning = function() {
var node = this.client.getNode(this._currentNodeId),
baseId = node.getBaseId(),
base = this.client.getNode(baseId),
type = base.getAttribute('name');
ForgeActionButton.prototype.isRunning = function(node) {
var baseId,
base,
type;

node = node || this.client.getNode(this._currentNodeId);
baseId = node.getBaseId();
base = this.client.getNode(baseId);
type = base.getAttribute('name');

if (type === 'Execution') {
return node.getAttribute('status') === 'running';
} else {
return this.isJobRunning(node);
} else if (type === 'Job') {
return this.isRunningJob(node);
}
return false;
};

ForgeActionButton.prototype.isJobRunning = function(job) {
ForgeActionButton.prototype.isRunningJob = function(job) {
var status = job.getAttribute('status');

return (status === 'running' || status === 'pending') &&
Expand All @@ -373,15 +378,22 @@ define([

ForgeActionButton.prototype.stopJob = function(job) {
var jobHash,
jobId,
secret;

job = job || this.client.getNode(this._currentNodeId);
jobId = job.getId();
jobHash = job.getAttribute('jobId');
secret = job.getAttribute('secret');
if (!jobHash || !secret) {
this.logger.error('Cannot stop job. Missing jobHash or secret');
return;
}

this.client.delAttributes(jobId, 'jobId');
this.client.delAttributes(jobId, 'secret');
this.client.setAttributes(jobId, 'status', 'canceled');

return this._executor.cancelJob(jobHash, secret)
.then(() => this.logger.info(`${jobHash} has been cancelled!`))
.fail(err => this.logger.error(`Job cancel failed: ${err}`));
Expand Down

0 comments on commit a7e08aa

Please sign in to comment.