Skip to content

Commit

Permalink
monitor debug
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRunfola committed Feb 28, 2025
1 parent b0d4e74 commit d335d63
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
29 changes: 25 additions & 4 deletions geoBoundaryBuilder/monitor/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ def get_worker_grid():
with get_db_connection() as conn:
with conn.cursor() as cur:
# Get all worker statuses
cur.execute("""
query = """
SELECT "STATUS_TYPE", "STATUS", "TIME", "SOURCE_DATE"
FROM worker_status
WHERE "STATUS_TYPE" LIKE '%_WORKER'
""")
"""

logging.info(f"Executing query: {query}")
cur.execute(query)
rows = cur.fetchall()
logging.info(f"Found {len(rows)} worker status rows")

# Process into grid format
grid_data = []
Expand All @@ -52,19 +56,36 @@ def get_worker_grid():
iso = parts[0]
adm = parts[1].replace('ADM', '')
status = row[1]
timestamp = row[2].replace(tzinfo=ZoneInfo('UTC')).astimezone(ZoneInfo('America/New_York')).isoformat() if row[2] else None

# Handle TIME column safely
timestamp = None
if row[2]:
try:
timestamp = row[2].replace(tzinfo=ZoneInfo('UTC')).astimezone(ZoneInfo('America/New_York')).isoformat()
except Exception as time_e:
logging.error(f"Error processing time for {iso}_ADM{adm}: {time_e}")

# Handle SOURCE_DATE column safely
source_date = None
if row[3]:
try:
source_date = row[3].replace(tzinfo=ZoneInfo('UTC')).astimezone(ZoneInfo('America/New_York')).isoformat()
except Exception as date_e:
logging.error(f"Error processing source date for {iso}_ADM{adm}: {date_e}")

grid_data.append({
'iso': iso,
'adm': adm,
'status': status,
'time': timestamp,
'source_date': row[3].replace(tzinfo=ZoneInfo('UTC')).astimezone(ZoneInfo('America/New_York')).isoformat() if row[3] else None
'source_date': source_date
})

return jsonify({'grid_data': grid_data})
except Exception as e:
logging.error(f"Error getting worker grid data: {e}")
import traceback
logging.error(traceback.format_exc())
return jsonify({'error': str(e)}), 500

@app.route('/api/stats')
Expand Down
32 changes: 18 additions & 14 deletions geoBoundaryBuilder/monitor/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,22 @@ <h2>Worker Status Grid</h2>

<script>
function formatDateEST(isoString) {
if (!isoString) return 'None';
const date = new Date(isoString);
return date.toLocaleString('en-US', {
timeZone: 'America/New_York',
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: true
});
if (!isoString) return '-';
try {
const date = new Date(isoString);
if (isNaN(date.getTime())) return '-'; // Invalid date
return date.toLocaleString('en-US', {
timeZone: 'America/New_York',
year: 'numeric',
month: 'short',
day: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
} catch (e) {
console.error('Error formatting date:', e, isoString);
return '-';
}
}

function getTimeDifferenceInMinutes(isoString) {
Expand Down Expand Up @@ -382,10 +386,10 @@ <h2>Worker Status Grid</h2>
let mostRecentSourceDate = null;

isoData.forEach((value) => {
if (!mostRecentTime || (value.time && new Date(value.time) > new Date(mostRecentTime))) {
if (value && value.time && (!mostRecentTime || new Date(value.time) > new Date(mostRecentTime))) {
mostRecentTime = value.time;
}
if (value.source_date && (!mostRecentSourceDate || new Date(value.source_date) > new Date(mostRecentSourceDate))) {
if (value && value.source_date && (!mostRecentSourceDate || new Date(value.source_date) > new Date(mostRecentSourceDate))) {
mostRecentSourceDate = value.source_date;
}
});
Expand Down

0 comments on commit d335d63

Please sign in to comment.