From 2a0450a4d9ff55fdd5702caade7eeb0d7adcc936 Mon Sep 17 00:00:00 2001 From: Benedetta Date: Thu, 2 May 2024 12:26:01 +0200 Subject: [PATCH] burrodiarachidi --- pam/bin/main.ml | 7 ++++--- pam/bin/mq.ml | 12 ++++++++++++ pam/lib/datatypes.ml | 4 ++-- pam/lib/issuelib.ml | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/pam/bin/main.ml b/pam/bin/main.ml index f626026..7764872 100644 --- a/pam/bin/main.ml +++ b/pam/bin/main.ml @@ -32,6 +32,7 @@ let http_client (repos: Config.repo_data list) = in aux [] issues in let rec loop () = + let default_error_room = MatrixRoom.make "!KABwGlTSmXAbzCOhCX:goulash.lezzo.org" in (* TODO: remove hardcoded *) let _ = match Riot.receive_any () with | ListIssues -> @@ -39,7 +40,7 @@ let http_client (repos: Config.repo_data list) = let issues = Httpclient.make_get_request http_actor in Result.bind issues (check_alert_time now) - |> Result.map_error internal_failure + |> Result.map_error (internal_failure default_error_room) |> Result.fold ~ok:forgejo_issues ~error:List.singleton |> List.map (Riot.send_by_name ~name:_MQ_CLIENT) | m -> unhandled m @@ -59,9 +60,9 @@ let mq_client (mq_url, mq_user, mq_password) = let _ = try%lwt match Riot.receive_any ~after:one_second () with - | InternalFailure err -> + | InternalFailure (matrix_room, err) -> let _ = Pamlog.error [%string "Got error from Forgejo: %{err}"] in - Mq.mq_publish mq err + err |> Mq.error_msg_to_json_format matrix_room |> Mq.mq_publish mq | Reminder reminder -> let formatted = Issuelib.issue_data_to_json reminder in Mq.mq_publish mq formatted diff --git a/pam/bin/mq.ml b/pam/bin/mq.ml index bc9971c..c35ce75 100644 --- a/pam/bin/mq.ml +++ b/pam/bin/mq.ml @@ -32,3 +32,15 @@ let mq_publish {queue=_; channel=channel; connection=_} msg = Message.make msg |> Exchange.publish channel Exchange.default ~routing_key:"lanonna" in Lwt.return_unit + +let error_msg_to_json_format room_id error = + let open Yojson.Basic in + let content = [%string {|Pam รจ entrata in errore: %{error}| |}] in + let d = `Assoc [ + ("content", `String content); + ("source_message_id", `Null); + ("room_id", `String room_id); + ("as_reply", `Bool false); + ("as_markdown", `Bool true) + ] in + to_string d diff --git a/pam/lib/datatypes.ml b/pam/lib/datatypes.ml index 06cb06c..514a939 100644 --- a/pam/lib/datatypes.ml +++ b/pam/lib/datatypes.ml @@ -19,7 +19,7 @@ type Riot.Message.t += | LookupClient of client_id | ListIssues | Reminder of forgejo_issue_data - | InternalFailure of string + | InternalFailure of (MatrixRoom.t * string) let forgejo_issues issues = issues |> List.map (fun r -> Reminder r) -let internal_failure reason = InternalFailure reason +let internal_failure matrix_room reason = InternalFailure (matrix_room, reason) diff --git a/pam/lib/issuelib.ml b/pam/lib/issuelib.ml index ca2aa6a..658fef2 100644 --- a/pam/lib/issuelib.ml +++ b/pam/lib/issuelib.ml @@ -82,7 +82,7 @@ module Private = struct | None, _ -> Error [%string "Can't parse numbers from string hour: h=%{h}|m=%{m}|"] | _, None -> Error [%string "Can't parse numbers from string minute: h=%{h}|m=%{m}|"] end - | _ -> Error [%string "Malformed time: %{str}"]) + | _ -> Error [%string "Malformed time: |%{str}|%{date_str}|"]) end open Private