@@ -23,7 +23,6 @@ use tokio::task::JoinHandle;
2323use crate :: tracker:: statistics_importer:: StatisticsImporter ;
2424
2525const IMPORTER_API_IP : & str = "127.0.0.1" ;
26- const IMPORTER_API_PORT : u16 = 3002 ; // todo: use configuration option
2726
2827#[ derive( Clone ) ]
2928struct ImporterState {
@@ -34,7 +33,11 @@ struct ImporterState {
3433 pub torrent_info_update_interval : u64 ,
3534}
3635
37- pub fn start ( torrent_info_update_interval : u64 , tracker_statistics_importer : & Arc < StatisticsImporter > ) -> JoinHandle < ( ) > {
36+ pub fn start (
37+ importer_port : u16 ,
38+ torrent_info_update_interval : u64 ,
39+ tracker_statistics_importer : & Arc < StatisticsImporter > ,
40+ ) -> JoinHandle < ( ) > {
3841 let weak_tracker_statistics_importer = Arc :: downgrade ( tracker_statistics_importer) ;
3942
4043 tokio:: spawn ( async move {
@@ -55,7 +58,7 @@ pub fn start(torrent_info_update_interval: u64, tracker_statistics_importer: &Ar
5558 . route ( "/heartbeat" , post ( heartbeat_handler) )
5659 . with_state ( import_state) ;
5760
58- let addr = format ! ( "{IMPORTER_API_IP}:{IMPORTER_API_PORT }" ) ;
61+ let addr = format ! ( "{IMPORTER_API_IP}:{importer_port }" ) ;
5962
6063 info ! ( "Tracker statistics importer API server listening on http://{}" , addr) ;
6164
@@ -79,7 +82,7 @@ pub fn start(torrent_info_update_interval: u64, tracker_statistics_importer: &Ar
7982
8083 info ! ( "Running tracker statistics importer ..." ) ;
8184
82- if let Err ( e) = send_heartbeat ( ) . await {
85+ if let Err ( e) = send_heartbeat ( importer_port ) . await {
8386 error ! ( "Failed to send heartbeat from importer cronjob: {}" , e) ;
8487 }
8588
@@ -117,9 +120,9 @@ async fn heartbeat_handler(State(state): State<Arc<ImporterState>>) -> Json<Valu
117120}
118121
119122/// Send a heartbeat from the importer cronjob to the importer API.
120- async fn send_heartbeat ( ) -> Result < ( ) , reqwest:: Error > {
123+ async fn send_heartbeat ( importer_port : u16 ) -> Result < ( ) , reqwest:: Error > {
121124 let client = reqwest:: Client :: new ( ) ;
122- let url = format ! ( "http://{IMPORTER_API_IP}:{IMPORTER_API_PORT }/heartbeat" ) ;
125+ let url = format ! ( "http://{IMPORTER_API_IP}:{importer_port }/heartbeat" ) ;
123126
124127 client. post ( url) . send ( ) . await ?;
125128
0 commit comments