Skip to content

Commit

Permalink
Bug 1494572 - Use the 'cancel-all' task action when cancelling all jo…
Browse files Browse the repository at this point in the history
…bs for a push (#4076)

This will stop triggering the cancel action on every job and instead
trigger the cancel-all action once.
  • Loading branch information
helfi92 authored and edmorley committed Oct 1, 2018
1 parent e307fad commit 727d3fc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
9 changes: 4 additions & 5 deletions ui/job-view/pushes/PushHeader.jsx
Expand Up @@ -136,14 +136,13 @@ class PushHeader extends React.PureComponent {
cancelAllJobs() {
if (window.confirm('This will cancel all pending and running jobs for this push. It cannot be undone! Are you sure?')) {
const { push, isLoggedIn } = this.props;
const jobsCanCancel = push.jobList
.filter(({ state }) => state === 'running' || state === 'pending')
.map(({ id }) => id);
// Any job Id inside the push will do
const jobId = push.jobList[0].id;

if (!isLoggedIn) return;

JobModel.cancel(
jobsCanCancel,
JobModel.cancelAll(
jobId,
this.$rootScope.repoName,
this.ThResultSetStore,
this.thNotify,
Expand Down
30 changes: 28 additions & 2 deletions ui/models/job.js
Expand Up @@ -139,13 +139,39 @@ export default class JobModel {
}
}

// Any jobId inside the push will do
static async cancelAll(jobId, repoName, ThResultSetStore, thNotify) {
const job = await JobModel.get(repoName, jobId);
const decisionTaskId = await ThResultSetStore.getGeckoDecisionTaskId(job.result_set_id);
const results = await TaskclusterModel.load(decisionTaskId);
const cancelAllTask = results.actions.find(result => result.name === 'cancel-all');

try {
await TaskclusterModel.submit({
action: cancelAllTask,
decisionTaskId,
input: {},
staticActionVariables: results.staticActionVariables,
});
} catch (e) {
// The full message is too large to fit in a Treeherder
// notification box.
thNotify.send(
formatTaskclusterError(e),
'danger',
{ sticky: true });
}

thNotify.send('Request sent to cancel all jobs via action.json', 'success');
}

static async cancel(jobIds, repoName, ThResultSetStore, thNotify) {
const isManyJobs = jobIds.length > 1;

try {
if (isManyJobs) {
thNotify.send(
'Attempting to cancel all jobs via actions.json',
'Attempting to cancel selected jobs via actions.json',
'info');
}

Expand Down Expand Up @@ -175,7 +201,7 @@ export default class JobModel {
}
/* eslint-enable no-await-in-loop */

thNotify.send(`Request sent to cancel ${isManyJobs ? 'all jobs' : 'job'} via action.json`, 'success');
thNotify.send(`Request sent to cancel ${isManyJobs ? 'selected jobs' : 'job'} via action.json`, 'success');
} catch (e) {
thNotify.send(`Unable to cancel ${isManyJobs ? 'all jobs' : 'job'}`, 'danger', { sticky: true });
}
Expand Down
4 changes: 3 additions & 1 deletion ui/models/taskcluster.js
Expand Up @@ -3,12 +3,14 @@ import jsone from 'json-e';
import { Auth, Hooks } from 'taskcluster-client-web';
import { satisfiesExpression } from 'taskcluster-lib-scopes';


import taskcluster from '../helpers/taskcluster';
import { tcRootUrl } from '../helpers/url';

export default class TaskclusterModel {
static taskInContext(tagSetList, taskTags) {
return tagSetList.some(tagSet => Object.keys(tagSet)
return tagSetList
.some(tagSet => Object.keys(tagSet)
.every(tag => taskTags[tag] && taskTags[tag] === tagSet[tag]),
);
}
Expand Down

0 comments on commit 727d3fc

Please sign in to comment.