1
1
open Common
2
2
open Devkit
3
3
4
- type t = {
5
- state : State_t .state ;
6
- lock : Lwt_mutex .t ; (* * protect access to mutable string map `pipeline_statuses` *)
7
- }
4
+ let log = Log. from " state"
5
+
6
+ type t = { state : State_t .state }
8
7
9
8
let empty_repo_state () : State_t.repo_state = { pipeline_statuses = StringMap. empty }
10
9
11
10
let empty () : t =
12
11
let state = State_t. { repos = Stringtbl. empty () ; bot_user_id = None } in
13
- { state; lock = Lwt_mutex. create () }
12
+ { state }
14
13
15
14
let find_or_add_repo' state repo_url =
16
15
match Stringtbl. find_opt state.State_t. repos repo_url with
@@ -20,31 +19,23 @@ let find_or_add_repo' state repo_url =
20
19
Stringtbl. add state.State_t. repos repo_url new_repo;
21
20
new_repo
22
21
23
- let set_repo_state { state; lock } repo_url repo_state =
24
- Lwt_mutex. with_lock lock @@ fun () ->
25
- Stringtbl. replace state.repos repo_url repo_state;
26
- Lwt. return_unit
22
+ let set_repo_state { state } repo_url repo_state = Stringtbl. replace state.repos repo_url repo_state
23
+ let find_or_add_repo { state } repo_url = find_or_add_repo' state repo_url
27
24
28
- let find_or_add_repo { state; lock } repo_url =
29
- Lwt_mutex. with_lock lock @@ fun () -> find_or_add_repo' state repo_url |> Lwt. return
30
-
31
- let set_repo_pipeline_status { state; lock } repo_url ~pipeline ~(branches : Github_t.branch list ) ~status =
25
+ let set_repo_pipeline_status { state } repo_url ~pipeline ~(branches : Github_t.branch list ) ~status =
32
26
let set_branch_status branch_statuses =
33
27
let new_statuses = List. map (fun (b : Github_t.branch ) -> b.name, status) branches in
34
28
let init = Option. default StringMap. empty branch_statuses in
35
29
Some (List. fold_left (fun m (key , data ) -> StringMap. add key data m) init new_statuses)
36
30
in
37
- Lwt_mutex. with_lock lock @@ fun () ->
38
31
let repo_state = find_or_add_repo' state repo_url in
39
- repo_state.pipeline_statuses < - StringMap. update pipeline set_branch_status repo_state.pipeline_statuses;
40
- Lwt. return_unit
32
+ repo_state.pipeline_statuses < - StringMap. update pipeline set_branch_status repo_state.pipeline_statuses
41
33
42
34
let set_bot_user_id { state; _ } user_id = state.State_t. bot_user_id < - Some user_id
43
35
let get_bot_user_id { state; _ } = state.State_t. bot_user_id
44
- let log = Log. from " state"
45
36
46
37
let save { state; _ } path =
47
38
let data = State_j. string_of_state state |> Yojson.Basic. from_string |> Yojson.Basic. pretty_to_string in
48
39
match write_to_local_file ~data path with
49
- | Ok () -> Lwt. return @@ Ok ()
50
- | Error e -> Lwt. return @@ fmt_error " error while writing to local file %s: %s\n failed to save state" path e
40
+ | Ok () -> Ok ()
41
+ | Error e -> fmt_error " error while writing to local file %s: %s\n failed to save state" path e
0 commit comments