Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lufa/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ def jobs_data():
@login_required
def job_recap(tower_job_id):
"""Renders the job recap page for the given job ID."""
initial_job_state = get_backend_repository().get_job_status(tower_job_id)["state"]

return render_template(
"job_recap.html",
tower_job_id=tower_job_id,
initial_job_state=initial_job_state,
tower_job_template_name=get_backend_repository().get_job_template_name_by_job_id(tower_job_id),
)

Expand All @@ -74,9 +77,12 @@ def job_recap_data(tower_job_id):
@login_required
def job_callbacks(tower_job_id: int):
"""Renders the job callbacks page for the given job ID."""
initial_job_state = get_backend_repository().get_job_status(tower_job_id)["state"]

return render_template(
"job_callbacks.html",
tower_job_id=tower_job_id,
initial_job_state=initial_job_state,
tower_job_template_name=get_backend_repository().get_job_template_name_by_job_id(tower_job_id),
)

Expand All @@ -98,9 +104,12 @@ def job_callbacks_data(tower_job_id: int):
@login_required
def job_hosts_overview(tower_job_id: int):
"""Renders the job overview page for the given job ID."""
initial_job_state = get_backend_repository().get_job_status(tower_job_id)["state"]

return render_template(
"job_overview.html",
tower_job_id=tower_job_id,
initial_job_state=initial_job_state,
tower_job_template_name=get_backend_repository().get_job_template_name_by_job_id(tower_job_id),
)

Expand Down Expand Up @@ -152,9 +161,12 @@ def job_infos(tower_job_id: int):
awx_template_link = current_app.config["AWX_BASE_URL"] + "/#/templates/job_template/" + str(tower_job_template_id)
awx_job_link = current_app.config["AWX_BASE_URL"] + "/#/jobs/playbook/" + str(tower_job_id)

initial_job_state = get_backend_repository().get_job_status(tower_job_id)["state"]

return render_template(
"job_infos.html",
tower_job_id=tower_job_id,
initial_job_state=initial_job_state,
tower_job_template_name=get_backend_repository().get_job_template_name_by_job_id(tower_job_id),
tower_job_template_id=tower_job_template_id,
tower_user_name=tower_user_name,
Expand Down
19 changes: 13 additions & 6 deletions lufa/repository/backend_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,14 @@ def get_job_status(self, tower_job_id: int) -> JobStatus:
)

line = cursor.fetchone()
line["awx_tags"] = line["awx_tags"].split(",")
line["template_infos"] = line["template_infos"] = (
json.loads(line["template_infos"]) if line["template_infos"] else None
)
return line
if line is not None:
line["awx_tags"] = line["awx_tags"].split(",")
line["template_infos"] = line["template_infos"] = (
json.loads(line["template_infos"]) if line["template_infos"] else None
)
return line

raise ResourceNotFoundError(f"Job with id {tower_job_id} not found")

def get_job_task_callbacks(self, tower_job_id: int) -> list[JobTaskCallbacks]:
conn = self.db_manager.get_db_connection()
Expand Down Expand Up @@ -1011,7 +1014,11 @@ def get_job_status(self, tower_job_id: int) -> JobStatus:
(tower_job_id,),
)

return cursor.fetchone()
fetched = cursor.fetchone()
if fetched is not None:
return fetched

raise ResourceNotFoundError(f"Job with id {tower_job_id} not found")

def get_job_task_callbacks(self, tower_job_id: int) -> list[JobTaskCallbacks]:
conn = self.db_manager.get_db_connection()
Expand Down
5 changes: 4 additions & 1 deletion lufa/static/status-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ function getStatusElement(state) {
badge.className = 'badge';
badge.innerHTML = 'error';
badge.style.backgroundColor = 'purple';
} else {
} else if (state === 'failed') {
badge.className = 'badge bg-danger';
badge.innerHTML = 'failed';
} else {
badge.className = 'badge bg-secondary';
badge.innerHTML = 'unknown';
}
return badge;
}
Expand Down
4 changes: 4 additions & 0 deletions lufa/templates/basic_job.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ <h1>Job {{ tower_job_id }} - {{ tower_job_template_name }}</h1>
<script nonce="{{crp_nonce}}">

$(document).ready(() => {
// set initial job state
let initialJobState = "{{ initial_job_state | default('unknown') }}";
writeJobStatus(initialJobState);

globalThis.refresher.setUpdater(refresher => {
let jobState = "";

Expand Down
Loading