This commit is contained in:
@@ -109,7 +109,7 @@
|
|||||||
"refId": "A"
|
"refId": "A"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"title": "Chamados Total",
|
"title": "Chamados em vigor",
|
||||||
"type": "stat"
|
"type": "stat"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -240,6 +240,8 @@ class APIClient:
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
all_tickets = []
|
all_tickets = []
|
||||||
|
page = 1
|
||||||
|
expected_total = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import json
|
import json
|
||||||
@@ -247,31 +249,54 @@ class APIClient:
|
|||||||
queue_ids = Config.get_queue_ids_list()
|
queue_ids = Config.get_queue_ids_list()
|
||||||
tickets_url = f"{self.base_url}{Config.API_TICKETS_ENDPOINT}"
|
tickets_url = f"{self.base_url}{Config.API_TICKETS_ENDPOINT}"
|
||||||
|
|
||||||
# Use showAll=true for open tickets as per API example
|
while True:
|
||||||
params = {
|
# Use showAll=true and paginate until all open tickets are fetched
|
||||||
'pageNumber': 1,
|
params = {
|
||||||
'status': 'open',
|
'pageNumber': page,
|
||||||
'showAll': 'true',
|
'status': 'open',
|
||||||
'queueIds': json.dumps(queue_ids),
|
'showAll': 'true',
|
||||||
'tagIds': '[]',
|
'queueIds': json.dumps(queue_ids),
|
||||||
'isGroup': 'false',
|
'tagIds': '[]',
|
||||||
'sortDir': 'ASC',
|
'isGroup': 'false',
|
||||||
'isSearching': 'false'
|
'sortDir': 'ASC',
|
||||||
}
|
'isSearching': 'false'
|
||||||
|
}
|
||||||
|
|
||||||
logger.info(f"Fetching open tickets from {tickets_url} with params: {params}")
|
logger.info(f"Fetching open tickets from {tickets_url} with params: {params}")
|
||||||
response = self.session.get(
|
response = self.session.get(
|
||||||
tickets_url,
|
tickets_url,
|
||||||
params=params,
|
params=params,
|
||||||
timeout=15
|
timeout=15
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if response.status_code != 200:
|
||||||
|
logger.error(f"Failed to fetch open tickets: {response.status_code} - {response.text}")
|
||||||
|
break
|
||||||
|
|
||||||
if response.status_code == 200:
|
|
||||||
result = response.json()
|
result = response.json()
|
||||||
all_tickets = result.get('tickets', [])
|
page_tickets = result.get('tickets', [])
|
||||||
logger.info(f"Fetched {len(all_tickets)} open tickets")
|
|
||||||
else:
|
if expected_total is None and isinstance(result.get('count'), int):
|
||||||
logger.error(f"Failed to fetch open tickets: {response.status_code} - {response.text}")
|
expected_total = result.get('count')
|
||||||
|
|
||||||
|
if not page_tickets:
|
||||||
|
break
|
||||||
|
|
||||||
|
all_tickets.extend(page_tickets)
|
||||||
|
|
||||||
|
has_more = result.get('hasMore')
|
||||||
|
if isinstance(has_more, bool):
|
||||||
|
if not has_more:
|
||||||
|
break
|
||||||
|
elif expected_total is not None:
|
||||||
|
if len(all_tickets) >= expected_total:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
page += 1
|
||||||
|
|
||||||
|
logger.info(f"Fetched {len(all_tickets)} open tickets (all pages)")
|
||||||
|
|
||||||
except requests.exceptions.RequestException as e:
|
except requests.exceptions.RequestException as e:
|
||||||
logger.error(f"Error fetching open tickets: {str(e)}")
|
logger.error(f"Error fetching open tickets: {str(e)}")
|
||||||
@@ -280,7 +305,7 @@ class APIClient:
|
|||||||
|
|
||||||
def get_total_open_tickets(self) -> int:
|
def get_total_open_tickets(self) -> int:
|
||||||
"""
|
"""
|
||||||
Fetch total number of open tickets using showAll=true
|
Fetch total number of open tickets using full pagination
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
int: Total number of open tickets
|
int: Total number of open tickets
|
||||||
@@ -289,45 +314,7 @@ class APIClient:
|
|||||||
logger.error("Not authenticated. Please login first.")
|
logger.error("Not authenticated. Please login first.")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
try:
|
open_tickets = self.get_open_tickets()
|
||||||
import json
|
total_open = len(open_tickets)
|
||||||
|
logger.info(f"Fetched total open tickets: {total_open}")
|
||||||
queue_ids = Config.get_queue_ids_list()
|
return total_open
|
||||||
tickets_url = f"{self.base_url}{Config.API_TICKETS_ENDPOINT}"
|
|
||||||
|
|
||||||
params = {
|
|
||||||
'pageNumber': 1,
|
|
||||||
'status': 'open',
|
|
||||||
'showAll': 'true',
|
|
||||||
'queueIds': json.dumps(queue_ids),
|
|
||||||
'tagIds': '[]',
|
|
||||||
'isGroup': 'false',
|
|
||||||
'sortDir': 'DESC',
|
|
||||||
'isSearching': 'false'
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info(f"Fetching total open tickets from {tickets_url} with params: {params}")
|
|
||||||
response = self.session.get(
|
|
||||||
tickets_url,
|
|
||||||
params=params,
|
|
||||||
timeout=15
|
|
||||||
)
|
|
||||||
|
|
||||||
if response.status_code == 200:
|
|
||||||
result = response.json()
|
|
||||||
total = result.get('count')
|
|
||||||
if isinstance(total, int):
|
|
||||||
logger.info(f"Fetched total open tickets: {total}")
|
|
||||||
return total
|
|
||||||
|
|
||||||
tickets = result.get('tickets', [])
|
|
||||||
fallback_total = len(tickets) if isinstance(tickets, list) else 0
|
|
||||||
logger.info(f"Open tickets count field not found, fallback total: {fallback_total}")
|
|
||||||
return fallback_total
|
|
||||||
|
|
||||||
logger.error(f"Failed to fetch total open tickets: {response.status_code} - {response.text}")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
except requests.exceptions.RequestException as e:
|
|
||||||
logger.error(f"Error fetching total open tickets: {str(e)}")
|
|
||||||
return 0
|
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ def background_data_updater():
|
|||||||
}
|
}
|
||||||
|
|
||||||
open_tickets = client.get_open_tickets()
|
open_tickets = client.get_open_tickets()
|
||||||
cached_total_open_tickets = client.get_total_open_tickets()
|
cached_total_open_tickets = len(open_tickets)
|
||||||
cached_longest_tickets = DataFormatter.format_longest_tickets(open_tickets, limit=5)
|
cached_longest_tickets = DataFormatter.format_longest_tickets(open_tickets, limit=5)
|
||||||
last_dashboard_update = datetime.now()
|
last_dashboard_update = datetime.now()
|
||||||
logger.info("Background updater: Successfully updated dashboard metrics")
|
logger.info("Background updater: Successfully updated dashboard metrics")
|
||||||
|
|||||||
Reference in New Issue
Block a user