Merge pull request #1278 from jakemcdermott/bug-1276

fix stats bar issue for adhoc jobs + account for 'check' type project update jobs
This commit is contained in:
Jake McDermott 2018-04-09 09:56:17 -04:00 committed by GitHub
commit 4a9bf0e46d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 33 deletions

View File

@ -184,7 +184,6 @@ function getInventoryDetails () {
function getProjectDetails () {
const project = resource.model.get('summary_fields.project');
const projectUpdate = resource.model.get('summary_fields.project_update');
if (!project) {
return null;
@ -195,17 +194,32 @@ function getProjectDetails () {
const value = $filter('sanitize')(project.name);
const tooltip = strings.get('resourceTooltips.PROJECT');
if (projectUpdate) {
const update = {
link: `/#/jobz/project/${projectUpdate.id}`,
tooltip: strings.get('resourceTooltips.PROJECT_UPDATE'),
status: projectUpdate.status,
};
return { label, link, value, tooltip };
}
return { label, link, value, tooltip, update };
function getProjectStatusDetails (projectStatus) {
const project = resource.model.get('summary_fields.project');
const jobStatus = projectStatus || resource.model.get('summary_fields.project_update.status');
if (!project) {
return null;
}
return { label, link, value, tooltip };
return jobStatus;
}
function getProjectUpdateDetails (updateId) {
const project = resource.model.get('summary_fields.project');
const jobId = updateId || resource.model.get('summary_fields.project_update.id');
if (!project) {
return null;
}
const link = `/#/jobz/project/${jobId}`;
const tooltip = strings.get('resourceTooltips.PROJECT_UPDATE');
return { link, tooltip };
}
function getSCMRevisionDetails () {
@ -495,6 +509,8 @@ function AtJobDetailsController (
vm.sourceWorkflowJob = getSourceWorkflowJobDetails();
vm.inventory = getInventoryDetails();
vm.project = getProjectDetails();
vm.projectUpdate = getProjectUpdateDetails();
vm.projectStatus = getProjectStatusDetails();
vm.scmRevision = getSCMRevisionDetails();
vm.playbook = getPlaybookDetails();
vm.resultTraceback = getResultTracebackDetails();
@ -533,16 +549,15 @@ function AtJobDetailsController (
vm.deleteJob = deleteJob;
vm.toggleLabels = toggleLabels;
$scope.$watch(status.getStarted, value => { vm.started = getStartDetails(value); });
$scope.$watch(status.getJobStatus, value => { vm.status = getStatusDetails(value); });
$scope.$watch(status.getFinished, value => { vm.finished = getFinishDetails(value); });
const observe = (getter, transform, key) => {
$scope.$watch(getter, value => { vm[key] = transform(value); });
};
$scope.$watch(status.getProjectStatus, value => {
if (!value) return;
vm.project.update = vm.project.update || {};
vm.project.update.status = value;
});
observe(status.getStarted, getStartDetails, 'started');
observe(status.getJobStatus, getStatusDetails, 'status');
observe(status.getFinished, getFinishDetails, 'finished');
observe(status.getProjectUpdateId, getProjectUpdateDetails, 'projectUpdate');
observe(status.getProjectStatus, getProjectStatusDetails, 'projectStatus');
};
}

View File

@ -119,11 +119,11 @@
<div class="JobResults-resultRow" ng-if="vm.project">
<label class="JobResults-resultRowLabel">{{ vm.project.label }}</label>
<div class="JobResults-resultRowText">
<a href="{{ vm.project.update.link }}"
ng-if="vm.project.update"
aw-tool-tip="{{ vm.project.update.tooltip }}"
<a href="{{ vm.projectUpdate.link }}"
ng-if="vm.projectUpdate"
aw-tool-tip="{{ vm.projectUpdate.tooltip }}"
data-placement="top">
<i class="JobResults-statusResultIcon fa icon-job-{{ vm.project.update.status }}"></i>
<i ng-if="vm.projectStatus" class="JobResults-statusResultIcon fa icon-job-{{ vm.projectStatus }}"></i>
</a>
<a href="{{ vm.project.link }}"
aw-tool-tip="{{ vm.project.tooltip }}"

View File

@ -95,7 +95,7 @@ function init () {
}
});
$scope.$on(resource.ws.events, handleSocketEvent);
$scope.$on(resource.ws.events, handleJobEvent);
$scope.$on(resource.ws.status, handleStatusEvent);
if (!status.isRunning()) {
@ -107,7 +107,7 @@ function handleStatusEvent (scope, data) {
status.pushStatusEvent(data);
}
function handleSocketEvent (scope, data) {
function handleJobEvent (scope, data) {
engine.pushJobEvent(data);
status.pushJobEvent(data);

View File

@ -18,7 +18,7 @@ function JobsStrings (BaseString) {
ns.status = {
RUNNING: t.s('The host status bar will update when the job is complete.'),
UNAVAILABLE: t.s('Host status information for this job unavailable.'),
UNAVAILABLE: t.s('Host status information for this job is unavailable.'),
};
ns.resourceTooltips = {

View File

@ -2,7 +2,9 @@ const JOB_START = 'playbook_on_start';
const JOB_END = 'playbook_on_stats';
const PLAY_START = 'playbook_on_play_start';
const TASK_START = 'playbook_on_task_start';
const HOST_STATUS_KEYS = ['dark', 'failures', 'changed', 'ok', 'skipped'];
const FINISHED = ['successful', 'failed', 'error'];
let moment;
@ -14,13 +16,16 @@ function JobStatusService (_moment_) {
this.created = resource.model.get('created');
this.job = resource.model.get('id');
this.jobType = resource.model.get('type');
this.project = resource.model.get('project');
this.elapsed = resource.model.get('elapsed');
this.started = resource.model.get('started');
this.finished = resource.model.get('finished');
this.jobStatus = resource.model.get('status');
this.projectStatus = resource.model.get('summary_fields.project_update.status');
this.projectUpdateId = resource.model.get('summary_fields.project_update.id');
this.latestTime = null;
this.playCount = null;
this.taskCount = null;
this.hostCount = null;
@ -39,6 +44,7 @@ function JobStatusService (_moment_) {
this.setJobStatus(data.status);
} else if (isProjectEvent) {
this.setProjectStatus(data.status);
this.setProjectUpdateId(data.unified_job_id);
}
};
@ -52,12 +58,12 @@ function JobStatusService (_moment_) {
if (isLatest) {
this.counter = data.counter;
this.latestTime = data.created;
this.elapsed = moment(data.created).diff(this.created, 'seconds');
this.jobStatus = _.get(data, ['summary_fields', 'job', 'status']);
}
if (data.event === JOB_START) {
this.started = data.created;
this.started = this.started || data.created;
}
if (data.event === PLAY_START) {
@ -97,14 +103,12 @@ function JobStatusService (_moment_) {
};
this.updateStats = () => {
if (!this.statsEvent) {
return;
}
this.updateHostCounts();
this.setFinished(this.statsEvent.created);
this.setJobStatus(this.statsEvent.failed ? 'failed' : 'successful');
if (this.statsEvent) {
this.setFinished(this.statsEvent.created);
this.setJobStatus(this.statsEvent.failed ? 'failed' : 'successful');
}
};
this.isRunning = () => (Boolean(this.started) && !this.finished) ||
@ -112,12 +116,16 @@ function JobStatusService (_moment_) {
(this.jobStatus === 'pending') ||
(this.jobStatus === 'waiting');
this.isExpectingStatsEvent = () => (this.jobType === 'job') ||
(this.jobType === 'project_update');
this.getPlayCount = () => this.playCount;
this.getTaskCount = () => this.taskCount;
this.getHostCount = () => this.hostCount;
this.getHostStatusCounts = () => this.hostStatusCounts || {};
this.getJobStatus = () => this.jobStatus;
this.getProjectStatus = () => this.projectStatus;
this.getProjectUpdateId = () => this.projectUpdateId;
this.getElapsed = () => this.elapsed;
this.getStatsEvent = () => this.statsEvent;
this.getStarted = () => this.started;
@ -125,12 +133,26 @@ function JobStatusService (_moment_) {
this.setJobStatus = status => {
this.jobStatus = status;
if (!this.isExpectingStatsEvent() && _.includes(FINISHED, status)) {
if (this.latestTime) {
this.setFinished(this.latestTime);
if (!this.started && this.elapsed) {
this.started = moment(this.latestTime).subtract(this.elapsed, 'seconds');
}
}
}
};
this.setProjectStatus = status => {
this.projectStatus = status;
};
this.setProjectUpdateId = id => {
this.projectUpdateId = id;
};
this.setFinished = time => {
this.finished = time;
};