Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
Merge pull request #366 from lightsofapollo/bug-1113281
Browse files Browse the repository at this point in the history
Bug 1113281 - Update retrigger logic to always hit new retrigger endpoint
  • Loading branch information
lightsofapollo committed Feb 20, 2015
2 parents a50c625 + f48584b commit 3103fad
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 17 deletions.
12 changes: 11 additions & 1 deletion webapp/app/js/models/job.js
Expand Up @@ -84,8 +84,18 @@ treeherder.factory('ThJobModel', [
});
};

ThJobModel.retrigger = function(repoName, pk, config) {
config = config || {};
var timeout = config.timeout || null;

return $http.post(ThJobModel.get_uri(repoName)+pk+"/retrigger/",
{timeout:timeout})
.then(function(response) {
return new ThJobModel(response.data);
});
};

ThJobModel.cancel = function(repoName, pk, config) {
// a static method to retrieve a single instance of ThJobModel
config = config || {};
var timeout = config.timeout || null;

Expand Down
57 changes: 42 additions & 15 deletions webapp/app/plugins/controller.js
Expand Up @@ -222,37 +222,64 @@ treeherder.controller('PluginCtrl', [
}
});

$scope.canRetrigger = function() {
return ($scope.job && $scope.artifacts && _.has($scope.artifacts, "buildapi"));
};

$scope.canCancel = function() {
return $scope.job && $scope.artifacts && _.has($scope.artifacts, "buildapi") &&
($scope.job.state === "pending" || $scope.job.state === "running");
return $scope.job &&
($scope.job.state === "pending" || $scope.job.state === "running");
};

/**
* Get the build_id needed to cancel or retrigger from the currently
* selected job.
*/
var getRequestId = function() {
var getBuildbotRequestId = function() {
if ($scope.artifacts.buildapi) {
return $scope.artifacts.buildapi.blob.request_id;
} else {
// this is super unlikely since we'd need to have at least one of those
// artifacts to even create the job in treeherder. This is just a fallback...
thNotify.send("Unable to get request id for retrigger/cancel", "danger", true);
return null;
}
};

$scope.retriggerJob = function() {
thBuildApi.retriggerJob($scope.repoName, getRequestId());
// The logic here is somewhat complicated because we need to support
// two use cases the first is the case where we notify a system
// other then buildbot that a retrigger has been requested. The
// second is when we have the buildapi id and need to send a request
// to the self serve api (which does not listen over pulse!).
ThJobModel.retrigger($scope.repoName, $scope.job.id).then(function() {
// XXX: Remove this after 1134929 is resolved.
var requestId = getBuildbotRequestId();
if (requestId) {
return thBuildApi.retriggerJob($scope.repoName, requestId);
}
}).catch(function(e){
// Always send a message even if we have no idea what the error
// is.
var message = "Unable to send retrigger"

// If we can figure out something from the server return that.
if (e && e.data && e.data.detail) {
message += ': ' + e.data.detail;
}

thNotify.send(message, "danger", true)
});
};

$scope.cancelJob = function() {
thBuildApi.cancelJob($scope.repoName, getRequestId()).then(function() {
ThJobModel.cancel($scope.repoName, $scope.job.id);
// See note in retrigger logic.
ThJobModel.cancel($scope.repoName, $scope.job.id).then(function() {
// XXX: Remove this after 1134929 is resolved.
var requestId = getBuildbotRequestId();
if (requestId) {
return thBuildApi.cancelJob($scope.repoName, requestId);
}
}).catch(function(e) {
var message = "Unable to cancel job"

// If we can figure out something from the server return that.
if (e && e.data && e.data.detail) {
message += ': ' + e.data.detail;
}

thNotify.send(message, "danger", true)
});
};

Expand Down
2 changes: 1 addition & 1 deletion webapp/app/plugins/pluginpanel.html
Expand Up @@ -86,7 +86,7 @@
<span class="fa fa-times-circle cancel-job-icon dim-half"></span>
</a>
</li>
<li ng-show="canRetrigger()">
<li>
<a title="Retrigger this job"
class="icon-green"
href="" prevent-default-on-left-click
Expand Down

0 comments on commit 3103fad

Please sign in to comment.