upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index b709d44..494342c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,6 +3,7 @@ mod db;
3mod discovery; 3mod discovery;
4mod git_mirror; 4mod git_mirror;
5mod health; 5mod health;
6mod http_health;
6mod nostr_mirror; 7mod nostr_mirror;
7mod signing; 8mod signing;
8 9
@@ -70,6 +71,24 @@ async fn run_daemon(config: config::ResolvedConfig, db: db::MirrorDb) -> Result<
70 let db = Arc::new(db); 71 let db = Arc::new(db);
71 let config = Arc::new(config); 72 let config = Arc::new(config);
72 73
74 let (cycle_count_tx, cycle_count_rx) = tokio::sync::watch::channel(0u64);
75 let (last_cycle_ok_tx, last_cycle_ok_rx) = tokio::sync::watch::channel(true);
76
77 let health_state = Arc::new(http_health::HealthState {
78 started_at: std::time::Instant::now(),
79 cycle_count: cycle_count_rx,
80 last_cycle_ok: last_cycle_ok_rx,
81 db_path: config.storage.database.display().to_string(),
82 });
83
84 let health_port = config.storage.health_port;
85 let health_state_clone = health_state.clone();
86 tokio::spawn(async move {
87 if let Err(e) = http_health::start_health_server(health_port, health_state_clone).await {
88 tracing::error!(error = %e, "health server failed");
89 }
90 });
91
73 let servers = health::verify_all_servers(&config.servers.known).await; 92 let servers = health::verify_all_servers(&config.servers.known).await;
74 let healthy: Vec<_> = servers 93 let healthy: Vec<_> = servers
75 .values() 94 .values()
@@ -101,19 +120,28 @@ async fn run_daemon(config: config::ResolvedConfig, db: db::MirrorDb) -> Result<
101 config.discovery.poll_interval_secs 120 config.discovery.poll_interval_secs
102 ); 121 );
103 122
123 let mut cycle_count: u64 = 0;
124
104 loop { 125 loop {
105 tokio::select! { 126 tokio::select! {
106 _ = interval.tick() => { 127 _ = interval.tick() => {
107 if let Err(e) = mirror_cycle( 128 let result = mirror_cycle(
108 &config, 129 &config,
109 &db, 130 &db,
110 &nostr_client, 131 &nostr_client,
111 &mirror, 132 &mirror,
112 &nostr_mirror, 133 &nostr_mirror,
113 &healthy, 134 &healthy,
114 ).await { 135 ).await;
115 tracing::error!(error = %e, "mirror cycle failed"); 136
137 match &result {
138 Ok(()) => tracing::info!("mirror cycle complete"),
139 Err(e) => tracing::error!(error = %e, "mirror cycle failed"),
116 } 140 }
141
142 cycle_count += 1;
143 let _ = cycle_count_tx.send(cycle_count);
144 let _ = last_cycle_ok_tx.send(result.is_ok());
117 } 145 }
118 _ = tokio::signal::ctrl_c() => { 146 _ = tokio::signal::ctrl_c() => {
119 tracing::info!("shutting down"); 147 tracing::info!("shutting down");