@@ -1016,22 +1016,22 @@ public isolated function mapToService(types:Service serviceRecord, string runtim
10161016// Periodically mark runtimes as OFFLINE if heartbeat is too old
10171017public isolated function markOfflineRuntimes() returns error ? {
10181018 log : printDebug (" Marking offline runtimes" );
1019- time : Utc now = time : utcNow ();
1020- // Calculate the threshold timestamp
1021- time : Utc threshold = time : utcAddSeconds (now , -< decimal > heartbeatTimeoutSeconds );
10221019
1023- // Convert threshold to H2 datetime format
1024- string thresholdStr = check convertUtcToDbDateTime (threshold );
1025-
1026- // Update all runtimes whose last_heartbeat is too old and not already OFFLINE
1020+ // Use database native timestamp functions for reliable comparison
1021+ // TIMESTAMPDIFF and DATE_SUB work in both H2 (in MySQL mode) and MySQL
10271022 sql : ParameterizedQuery updateQuery = `
10281023 UPDATE runtimes
10291024 SET status = 'OFFLINE'
10301025 WHERE status != 'OFFLINE'
10311026 AND last_heartbeat IS NOT NULL
1032- AND last_heartbeat < ${ thresholdStr }
1027+ AND TIMESTAMPDIFF(SECOND, last_heartbeat, CURRENT_TIMESTAMP) > ${ heartbeatTimeoutSeconds }
10331028 ` ;
1034- sql : ExecutionResult _ = check dbClient -> execute (updateQuery );
1029+ sql : ExecutionResult result = check dbClient -> execute (updateQuery );
1030+
1031+ int ? affectedCount = result .affectedRowCount ;
1032+ if affectedCount is int && affectedCount > 0 {
1033+ log : printInfo (string ` Marked ${affectedCount } runtime(s) as OFFLINE` );
1034+ }
10351035}
10361036
10371037// Process delta heartbeat with hash validation
@@ -2175,10 +2175,10 @@ public isolated function deleteProject(string projectId) returns error? {
21752175public isolated function createComponent(types : ComponentInput component ) returns types : Component | error ? {
21762176 string componentId = uuid : createType1AsString ();
21772177 string componentTypeValue = component .componentType .toString ();
2178-
2178+
21792179 // Use displayName if provided, otherwise fall back to name
21802180 string displayName = component ?.displayName ?: component .name ;
2181-
2181+
21822182 sql : ParameterizedQuery insertQuery = ` INSERT INTO components (component_id, project_id, name, display_name, description, component_type, created_by)
21832183 VALUES (${componentId }, ${component .projectId }, ${component .name }, ${displayName }, ${component .description }, ${componentTypeValue }, ${component .createdBy })` ;
21842184 var result = dbClient -> execute (insertQuery );
0 commit comments