From a00fe26a399d77f52feb2fff1b79c035628c99d1 Mon Sep 17 00:00:00 2001 From: Timo Huber Date: Thu, 6 Feb 2025 15:05:10 +0100 Subject: [PATCH 1/3] add database label to contact service logs --- pool/app/job/contact_job/inactivity.ml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/pool/app/job/contact_job/inactivity.ml b/pool/app/job/contact_job/inactivity.ml index 1ddf213bd..52a0686dc 100644 --- a/pool/app/job/contact_job/inactivity.ml +++ b/pool/app/job/contact_job/inactivity.ml @@ -58,18 +58,25 @@ let handle_contact_warnings pool warn_after = warning_notification_events pool contacts_to_warn ;; -let handle_events pool message = function +let handle_events pool message = + let tags = Database.(Logger.Tags.create pool) in + function | Error err -> let open Pool_common in Logs.err ~src (fun m -> m + ~tags "%s: An error occurred while making events: %s" message (Utils.error_to_string Language.En err)); Utils.failwith err | Ok (emails, events) -> Logs.info ~src (fun m -> - m "%s: Found %i contacts to notify due to inactivity" message (CCList.length events)); + m + ~tags + "%s: Found %i contacts to notify due to inactivity" + message + (CCList.length events)); let%lwt () = Email.handle_event pool (Email.BulkSent emails) in events |> Lwt_list.iter_s (Contact.handle_event pool) ;; @@ -82,11 +89,10 @@ let run_by_tenant pool = in let%lwt () = handle_disable_contacts pool disable_after warn_after - >|> handle_events pool "Pausing inactive users:" + >|> handle_events pool "Pausing inactive users" in let%lwt () = - handle_contact_warnings pool warn_after - >|> handle_events pool "Notify inactive users:" + handle_contact_warnings pool warn_after >|> handle_events pool "Notify inactive users" in Lwt.return_unit ;; From c8b2fe833d62dca48c35fb783421b2b260e6cfa5 Mon Sep 17 00:00:00 2001 From: Timo Huber Date: Thu, 6 Feb 2025 15:42:11 +0100 Subject: [PATCH 2/3] make sure duplicate contacts query only considers contact fields --- pool/app/custom_field/repo/repo.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pool/app/custom_field/repo/repo.ml b/pool/app/custom_field/repo/repo.ml index 1c143f525..63a0cbf56 100644 --- a/pool/app/custom_field/repo/repo.ml +++ b/pool/app/custom_field/repo/repo.ml @@ -293,11 +293,12 @@ module Sql = struct let where = {sql| WHERE pool_custom_fields.published_at IS NOT NULL + AND pool_custom_fields.model = ? AND pool_custom_fields.possible_duplicates_weight > 0 |sql} in - let request = select_sql where |> Caqti_type.unit ->* Repo_entity.t in - Database.collect pool request () + let request = select_sql where |> Repo_entity.Model.t ->* Repo_entity.t in + Database.collect pool request Entity.Model.Contact >|> multiple_to_entity pool Repo_entity.to_entity get_field_type get_id ;; end From f5358a7112dd8a1e907001301a3ea367c7147f67 Mon Sep 17 00:00:00 2001 From: Timo Huber Date: Thu, 6 Feb 2025 15:57:21 +0100 Subject: [PATCH 3/3] do not wrap exception in pool error --- pool/run/run.ml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pool/run/run.ml b/pool/run/run.ml index 0a48b2daa..d6f9ba8b7 100644 --- a/pool/run/run.ml +++ b/pool/run/run.ml @@ -83,10 +83,7 @@ let () = |> with_services services |> before_start (fun () -> (Lwt.async_exception_hook - := fun exn -> - Pool_message.Error.NotHandled (Printexc.to_string exn) - |> Pool_common.Utils.with_log_error ~src - |> ignore); + := fun exn -> Logger.log_exception ~src ~tags:Logs.Tag.empty exn |> ignore); Lwt.return @@ Logger.create_logs_dir ()) |> run ~commands ~log_reporter:Logger.reporter) ;;