Add peer management routes and server configuration services

This commit is contained in:
ImBenji
2025-08-04 16:46:08 +01:00
parent 773d209733
commit f1470a789e
7 changed files with 437 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
// Run a heartbeat to let supabase know that the client is still active.
import 'dart:io';
import 'dart:isolate';
import 'dart:math';
import 'package:supabase/supabase.dart';
import 'package:waylume_server/config/supabase_config.dart';
void initHeartbeat() {
// Run this on a separate thread.
Isolate.spawn((_) async {
// To avoid server deadlock
await Future.delayed(Duration(seconds: Random().nextInt(5)));
while (true) {
DateTime now = DateTime.now().toUtc();
await SUPABASE_CLIENT
.from("waylume_servers")
.update({ "last_heartbeat": now.toIso8601String() })
.eq("id", fromEnivronment("SERVER_ID")!);
print("Heartbeat sent to Supabase at ${now.toIso8601String()}");
// Wait 30 seconds before sending the next heartbeat
await Future.delayed(Duration(seconds: 30));
}
}, null);
}