From eef9ae9fb22c2bc82876a447ac41b81baef74265 Mon Sep 17 00:00:00 2001 From: Adhitya Logan Date: Tue, 13 Aug 2024 17:35:59 -0700 Subject: [PATCH] rm side effects + add docstring to get_escalations --- dashboard/src/t5gweb/api.py | 7 +++++-- dashboard/src/t5gweb/cache.py | 20 +++++++++++++------- dashboard/src/t5gweb/t5gweb.py | 4 +++- dashboard/src/t5gweb/taskmgr.py | 4 +++- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/dashboard/src/t5gweb/api.py b/dashboard/src/t5gweb/api.py index 29c5bd4..2aeecc7 100644 --- a/dashboard/src/t5gweb/api.py +++ b/dashboard/src/t5gweb/api.py @@ -1,4 +1,5 @@ """API endpoints for t5gweb""" +import json from flask import Blueprint, jsonify, request from flask_login import login_required @@ -12,7 +13,7 @@ get_stats, get_watchlist, ) -from t5gweb.libtelco5g import generate_stats, redis_get +from t5gweb.libtelco5g import generate_stats, redis_get, redis_set from t5gweb.utils import set_cfg BP = Blueprint("api", __name__, url_prefix="/api") @@ -61,7 +62,9 @@ def refresh(data_type): elif data_type == "bugs": get_bz_details(cfg) elif data_type == "escalations": - get_escalations(cfg) + cases = redis_get("cases") + escalations = get_escalations(cfg, cases) + redis_set("escalations", json.dumps(escalations)) return jsonify({"caching escalations": "ok"}) elif data_type == "watchlist": get_watchlist(cfg) diff --git a/dashboard/src/t5gweb/cache.py b/dashboard/src/t5gweb/cache.py index bde0cf4..d565021 100644 --- a/dashboard/src/t5gweb/cache.py +++ b/dashboard/src/t5gweb/cache.py @@ -62,16 +62,22 @@ def get_cases(cfg): libtelco5g.redis_set("cases", json.dumps(cases)) -def get_escalations(cfg): - """Get cases that have been escalated by querying the escalations JIRA board""" - cases = libtelco5g.redis_get("cases") +def get_escalations(cfg, cases): + """Get cases that have been escalated by querying the escalations JIRA board + + Args: + cfg: generated by utils.set_cfg() + cases: cases returned from portal API using the configured query + + Returns: + list: open Jira cards that have been escalated + """ if ( cases is None or cfg["jira_escalations_project"] is None or cfg["jira_escalations_label"] is None ): - libtelco5g.redis_set("escalations", json.dumps(None)) - return + return None logging.warning("getting escalated cases from JIRA") jira_conn = libtelco5g.jira_connection(cfg) @@ -87,10 +93,10 @@ def get_escalations(cfg): escalations = [] for card in escalated_cards: issue = jira_conn.issue(card) - case = issue.fields.customfield_12313441 + case = issue.fields.customfield_12313441 # SDFC Case Links in escalations proj. if case is not None: escalations.append(case) - libtelco5g.redis_set("escalations", json.dumps(escalations)) + return escalations def get_cards(cfg, self=None, background=False): diff --git a/dashboard/src/t5gweb/t5gweb.py b/dashboard/src/t5gweb/t5gweb.py index e47ff6e..0642bc0 100644 --- a/dashboard/src/t5gweb/t5gweb.py +++ b/dashboard/src/t5gweb/t5gweb.py @@ -152,7 +152,9 @@ def init_cache(): cache.get_issue_details(cfg) if escalations == {}: logging.warning("no escalations found in cache. refreshing...") - cache.get_escalations(cfg) + cases = libtelco5g.redis_get("cases") + escalations = cache.get_escalations(cfg, cases) + libtelco5g.redis_set("escalations", json.dumps(escalations)) if watchlist == {}: logging.warning("no watchlist found in cache. refreshing...") cache.get_watchlist(cfg) diff --git a/dashboard/src/t5gweb/taskmgr.py b/dashboard/src/t5gweb/taskmgr.py index 87941e7..1553229 100644 --- a/dashboard/src/t5gweb/taskmgr.py +++ b/dashboard/src/t5gweb/taskmgr.py @@ -196,7 +196,9 @@ def cache_data(data_type): elif data_type == "issues": cache.get_issue_details(cfg) elif data_type == "escalations": - cache.get_escalations(cfg) + cases = libtelco5g.redis_get("cases") + escalations = cache.get_escalations(cfg, cases) + libtelco5g.redis_set("escalations", json.dumps(escalations)) elif data_type == "watchlist": cache.get_watchlist(cfg) else: