Skip to content

Commit

Permalink
Build date note
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRunfola committed Feb 24, 2025
1 parent 67fb1e7 commit 38d4bac
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 9 deletions.
44 changes: 38 additions & 6 deletions geoBoundaryBuilder/modules/worker_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,51 @@ def update_status_in_db(conn, status_type, status, timestamp):
Update or insert a status record in the worker_status table
"""
try:
# Extract ISO and ADM from status_type
parts = status_type.split('_')
if len(parts) >= 3 and parts[1].startswith('ADM'):
iso = parts[0]
adm = parts[1].replace('ADM', '')

# Try to get build date from metadata file
build_date = None
meta_path = f"/sciclone/geograd/geoBoundaries/database/geoBoundariesDev/releaseData/gbOpen/{iso}/{parts[1]}/geoBoundaries-{iso}-{parts[1]}-metaData.json"
try:
if os.path.exists(meta_path):
with open(meta_path, 'r') as f:
meta_data = json.load(f)
build_date_str = meta_data.get('buildDate')
if build_date_str:
# Convert the date string to a timestamp
build_date = datetime.datetime.strptime(build_date_str, '%Y-%m-%d').replace(tzinfo=datetime.timezone.utc)
except Exception as e:
logging.warning(f"Could not read build date from metadata: {e}")

with conn.cursor() as cur:
# Upsert query to either update existing row or insert new row in worker_status table
# First, try to alter table to add BUILD_DATE column if it doesn't exist
try:
cur.execute("""
ALTER TABLE worker_status
ADD COLUMN IF NOT EXISTS "BUILD_DATE" TIMESTAMP WITH TIME ZONE
""")
conn.commit()
except Exception as e:
logging.warning(f"Could not add BUILD_DATE column: {e}")
conn.rollback()

# Upsert query including BUILD_DATE
upsert_query = """
INSERT INTO worker_status ("STATUS_TYPE", "STATUS", "TIME")
VALUES (%s, %s, %s)
INSERT INTO worker_status ("STATUS_TYPE", "STATUS", "TIME", "BUILD_DATE")
VALUES (%s, %s, %s, %s)
ON CONFLICT ("STATUS_TYPE")
DO UPDATE SET
"STATUS" = EXCLUDED."STATUS",
"TIME" = EXCLUDED."TIME"
"TIME" = EXCLUDED."TIME",
"BUILD_DATE" = EXCLUDED."BUILD_DATE"
"""
cur.execute(upsert_query, (status_type, status, timestamp))
cur.execute(upsert_query, (status_type, status, timestamp, build_date))
conn.commit()
logging.info(f"Updated worker_status for {status_type}: {status}")
logging.info(f"Updated worker_status for {status_type}: {status} (Build Date: {build_date})")
except Exception as e:
logging.error(f"Error updating worker_status in database: {e}")
conn.rollback()
Expand Down
3 changes: 2 additions & 1 deletion geoBoundaryBuilder/monitor/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def get_worker_grid():
'iso': iso,
'adm': adm,
'status': status,
'time': timestamp
'time': timestamp,
'build_date': row[3] if len(row) > 3 else None
})

return jsonify({'grid_data': grid_data})
Expand Down
29 changes: 27 additions & 2 deletions geoBoundaryBuilder/monitor/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@
display: inline-block;
}

.build-date {
font-size: 8px;
color: #666;
margin-top: 2px;
line-height: 1;
text-align: center;
}

.status-square:hover {
transform: scale(1.5);
z-index: 10;
Expand Down Expand Up @@ -350,11 +358,28 @@ <h2>Worker Status Grid</h2>
const status = isoMap.get(iso).get(adm.toString());

if (status) {
const container = document.createElement('div');
container.style.display = 'flex';
container.style.flexDirection = 'column';
container.style.alignItems = 'center';
container.style.padding = '2px';

const square = document.createElement('div');
square.className = 'status-square';
square.style.backgroundColor = getStatusColor(status.status, status.time);
square.title = `Status: ${status.status}\nUpdated: ${formatDateEST(status.time)}`;
cell.appendChild(square);
square.title = `Status: ${status.status}\nUpdated: ${formatDateEST(status.time)}${status.build_date ? '\nBuild Date: ' + status.build_date : ''}`;
container.appendChild(square);

if (status.build_date) {
const dateDiv = document.createElement('div');
dateDiv.className = 'build-date';
// Format build date as YYYY-MM-DD
const buildDate = new Date(status.build_date);
dateDiv.textContent = buildDate.toISOString().split('T')[0];
container.appendChild(dateDiv);
}

cell.appendChild(container);
}

row.appendChild(cell);
Expand Down

0 comments on commit 38d4bac

Please sign in to comment.