add auto_state_update client & server

This commit is contained in:
Swrup 2023-01-07 23:15:03 +01:00 committed by Gitea
parent cdd46850bf
commit b074eac54f
4 changed files with 55 additions and 8 deletions

View file

@ -1,3 +1,25 @@
let regularly_call_fun f v =
let () = Sys.set_signal Sys.sigalrm (Sys.Signal_handle (fun _ -> f ())) in
let (_ : Unix.interval_timer_status) =
Unix.setitimer Unix.ITIMER_REAL { Unix.it_interval = v; Unix.it_value = v }
in
()
let update_offline_user_state () =
(* TODO *)
()
let update_online_user_state () =
Hashtbl.filter_map_inplace
(fun _user_id state -> Some (Shared.State.auto_update state))
User.state_ht
let () =
regularly_call_fun update_online_user_state
(float_of_int Shared.State.auto_state_update_rate);
regularly_call_fun update_offline_user_state
(float_of_int Shared.State.auto_state_update_rate)
let () =
let logger = if App.log then Dream.logger else Fun.id in
Dream.run ~port:App.port @@ logger @@ Dream.memory_sessions