Merge pull request #760 from vaibhavmagarwal/backfill

Bug 1183923 - Front-end UI and publish to pulse for 'backfill' action
This commit is contained in:
Mauro Doglio 2015-07-16 13:35:45 +01:00
Родитель 09a5a1dc2d be0c80847e
Коммит 996518ed34
5 изменённых файлов: 61 добавлений и 0 удалений

Просмотреть файл

@ -333,6 +333,17 @@ class JobsModel(TreeherderModelBase):
"""
self._job_action_event(job, 'retrigger', requester)
def backfill(self, requester, job):
"""
Issue a "backfill" to the underlying build_system_type by scheduling a
pulse message.
:param requester str: The email address associated with the user who
made this request
:param job dict: A job object (typically a result of get_job)
"""
self._job_action_event(job, 'backfill', requester)
def cancel_job(self, requester, job):
"""
Cancel the given job and send an event to notify the build_system type

Просмотреть файл

@ -7,6 +7,7 @@ from rest_framework.response import Response
from rest_framework.decorators import detail_route
from rest_framework.reverse import reverse
from rest_framework.permissions import IsAuthenticated
from treeherder.webapp.api.permissions import IsStaffOrReadOnly
from treeherder.webapp.api.utils import (UrlQueryFilter, with_jobs,
oauth_required, get_option)
@ -147,6 +148,20 @@ class JobsViewSet(viewsets.ViewSet):
else:
return Response("No job with id: {0}".format(pk), 404)
@detail_route(methods=['post'], permission_classes=[IsStaffOrReadOnly])
@with_jobs
def backfill(self, request, project, jm, pk=None):
"""
Issue a "backfill" to the underlying build_system_type by scheduling a
pulse message.
"""
job = jm.get_job(pk)
if job:
jm.backfill(request.user.email, job[0])
return Response({"message": "backfilled job '{0}'".format(job[0]['job_guid'])})
else:
return Response("No job with id: {0}".format(pk), 404)
@with_jobs
@oauth_required
def create(self, request, project, jm):

Просмотреть файл

@ -94,6 +94,14 @@ treeherder.factory('ThJobModel', [
});
};
ThJobModel.backfill = function(repoName, pk, config) {
config = config || {};
var timeout = config.timeout || null;
return $http.post(ThJobModel.get_uri(repoName)+pk+"/backfill/",
{timeout:timeout});
};
ThJobModel.cancel = function(repoName, pk, config) {
config = config || {};
var timeout = config.timeout || null;

Просмотреть файл

@ -314,6 +314,26 @@ treeherder.controller('PluginCtrl', [
}
};
$scope.backfillJob = function() {
if ($scope.user.loggedin) {
// Only backfill if we have a valid loaded job, if the user
// tries to backfill eg. via shortcut before the load we warn them
if ($scope.job.id) {
ThJobModel.backfill($scope.repoName, $scope.job.id).then(function() {
thNotify.send("Request sent to backfill jobs", 'success');
}, function(e) {
// Generic error eg. the user doesn't have LDAP access
thNotify.send(
ThModelErrors.format(e, "Unable to send backfill"), 'danger');
});
} else {
thNotify.send("Job not yet loaded for backfill", 'warning');
}
} else {
thNotify.send("Must be logged in to backfill a job", 'danger');
}
};
$scope.cancelJob = function() {
if ($scope.user.loggedin) {
// See note in retrigger logic.

Просмотреть файл

@ -210,6 +210,13 @@
<label>Taskcluster:</label>
<span><a href="{{line.url}}" target="_blank">{{line.value}}</a></span>
</li>
<li class="small" ng-click="backfillJob()" ng-show="user.is_staff">
<label>
<a title="Trigger this jobtype on previous pushes.">
Backfill this job
</a>
</label>
</li>
</ul>
<div ng-if="job_detail_loading" class="overlay">