Skip to content

Commit

Permalink
Merge pull request #299 from adhil0/clean_get_escalations
Browse files Browse the repository at this point in the history
rm side effects + add docstring to get_escalations
  • Loading branch information
dcritch authored Aug 14, 2024
2 parents 59f063a + eef9ae9 commit 4eb3b66
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
7 changes: 5 additions & 2 deletions dashboard/src/t5gweb/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""API endpoints for t5gweb"""
import json

from flask import Blueprint, jsonify, request
from flask_login import login_required
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 13 additions & 7 deletions dashboard/src/t5gweb/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/t5gweb/t5gweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion dashboard/src/t5gweb/taskmgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 4eb3b66

Please sign in to comment.