This commit is contained in:
@@ -109,7 +109,7 @@
|
||||
"refId": "A"
|
||||
}
|
||||
],
|
||||
"title": "Chamados Total",
|
||||
"title": "Chamados em vigor",
|
||||
"type": "stat"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -240,6 +240,8 @@ class APIClient:
|
||||
return []
|
||||
|
||||
all_tickets = []
|
||||
page = 1
|
||||
expected_total = None
|
||||
|
||||
try:
|
||||
import json
|
||||
@@ -247,9 +249,10 @@ class APIClient:
|
||||
queue_ids = Config.get_queue_ids_list()
|
||||
tickets_url = f"{self.base_url}{Config.API_TICKETS_ENDPOINT}"
|
||||
|
||||
# Use showAll=true for open tickets as per API example
|
||||
while True:
|
||||
# Use showAll=true and paginate until all open tickets are fetched
|
||||
params = {
|
||||
'pageNumber': 1,
|
||||
'pageNumber': page,
|
||||
'status': 'open',
|
||||
'showAll': 'true',
|
||||
'queueIds': json.dumps(queue_ids),
|
||||
@@ -266,12 +269,34 @@ class APIClient:
|
||||
timeout=15
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
all_tickets = result.get('tickets', [])
|
||||
logger.info(f"Fetched {len(all_tickets)} open tickets")
|
||||
else:
|
||||
if response.status_code != 200:
|
||||
logger.error(f"Failed to fetch open tickets: {response.status_code} - {response.text}")
|
||||
break
|
||||
|
||||
result = response.json()
|
||||
page_tickets = result.get('tickets', [])
|
||||
|
||||
if expected_total is None and isinstance(result.get('count'), int):
|
||||
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:
|
||||
logger.error(f"Error fetching open tickets: {str(e)}")
|
||||
@@ -280,7 +305,7 @@ class APIClient:
|
||||
|
||||
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:
|
||||
int: Total number of open tickets
|
||||
@@ -289,45 +314,7 @@ class APIClient:
|
||||
logger.error("Not authenticated. Please login first.")
|
||||
return 0
|
||||
|
||||
try:
|
||||
import json
|
||||
|
||||
queue_ids = Config.get_queue_ids_list()
|
||||
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
|
||||
open_tickets = self.get_open_tickets()
|
||||
total_open = len(open_tickets)
|
||||
logger.info(f"Fetched total open tickets: {total_open}")
|
||||
return total_open
|
||||
|
||||
@@ -84,7 +84,7 @@ def background_data_updater():
|
||||
}
|
||||
|
||||
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)
|
||||
last_dashboard_update = datetime.now()
|
||||
logger.info("Background updater: Successfully updated dashboard metrics")
|
||||
|
||||
Reference in New Issue
Block a user