From c9409146fa69f84a839f25284f2e93e77b8b30db Mon Sep 17 00:00:00 2001 From: Tsvetozar Penov Date: Thu, 21 Nov 2024 12:55:38 +0100 Subject: [PATCH 1/3] MOve endpoint further down in start sequence --- lib/sanbase/application/application.ex | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/sanbase/application/application.ex b/lib/sanbase/application/application.ex index bbf156e62..68f91a6b4 100644 --- a/lib/sanbase/application/application.ex +++ b/lib/sanbase/application/application.ex @@ -300,21 +300,12 @@ defmodule Sanbase.Application do # Start the clickhouse read-only repos for different plans clickhouse_readonly_per_plan_children, - # Start the PubSub - {Phoenix.PubSub, name: Sanbase.PubSub}, - - # Start the Presence - SanbaseWeb.Presence, - - # Start the endpoint when the application starts - SanbaseWeb.Endpoint, + # Start the Task Supervisor + {Task.Supervisor, [name: Sanbase.TaskSupervisor]}, # Star the API call service Sanbase.ApiCallLimit.ETS, - # Start the Task Supervisor - {Task.Supervisor, [name: Sanbase.TaskSupervisor]}, - # Start telegram rate limiter. Used both in web and alerts Sanbase.ExternalServices.RateLimiting.Server.child_spec( :telegram_bot_rate_limiting_server, @@ -338,6 +329,15 @@ defmodule Sanbase.Application do # used in test env to another one, this one is unused start_in(Sanbase.AvailableSlugs, [:dev, :prod]), + # Start the PubSub + {Phoenix.PubSub, name: Sanbase.PubSub}, + + # Start the Presence + SanbaseWeb.Presence, + + # Start the endpoint when the application starts + SanbaseWeb.Endpoint, + # Process that starts test-only deps start_in(Sanbase.TestSetupService, [:test]), Sanbase.EventBus.children() From ffc49a83adcccfbcce64c061a6e0a7d0414f0546 Mon Sep 17 00:00:00 2001 From: Tsvetozar Penov Date: Thu, 21 Nov 2024 13:24:52 +0100 Subject: [PATCH 2/3] Catch json decode error email response --- lib/sanbase/alerts/alert.ex | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/sanbase/alerts/alert.ex b/lib/sanbase/alerts/alert.ex index 3ce4dc2a5..6e899c1e4 100644 --- a/lib/sanbase/alerts/alert.ex +++ b/lib/sanbase/alerts/alert.ex @@ -385,14 +385,19 @@ defimpl Sanbase.Alert, for: Any do payload_html = Earmark.as_html!(payload, breaks: true, timeout: nil, mapper: &Enum.map/2) name = Sanbase.Accounts.User.get_name(user) - Sanbase.TemplateMailer.send(user.email, Sanbase.Email.Template.alerts_template(), %{ - name: name, - username: name, - payload: payload_html - }) - |> case do - {:ok, _} -> :ok - {:error, reason} -> {:error, reason} + try do + case Sanbase.TemplateMailer.send(user.email, Sanbase.Email.Template.alerts_template(), %{ + name: name, + username: name, + payload: payload_html + }) do + {:ok, _} -> :ok + {:error, reason} -> {:error, %{reason: :email_send_fail, error: reason}} + end + rescue + e in Jason.DecodeError -> + Logger.error("Failed to decode Mailjet response: #{inspect(e)}") + {:error, "Invalid response from email provider"} end end From 870c7a9b002dbc8f6ef7d49ca3cf5eeb55a02b8b Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 21 Nov 2024 16:12:27 +0200 Subject: [PATCH 3/3] Improve error handling of allProjectsByFunction (#4483) --- .../list/selector/project_list_selector.ex | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/sanbase/project/list/selector/project_list_selector.ex b/lib/sanbase/project/list/selector/project_list_selector.ex index 0fca0bfb1..7a6aa0de9 100644 --- a/lib/sanbase/project/list/selector/project_list_selector.ex +++ b/lib/sanbase/project/list/selector/project_list_selector.ex @@ -93,9 +93,8 @@ defmodule Sanbase.Project.ListSelector do filters_combinator = Transform.args_to_filters_combinator(args) include_hidden = Map.get(args, :include_hidden, false) - base_slugs = base_slugs(base_projects_selector) - - with {:ok, included_slugs} <- included_slugs_by_filters(filters, filters_combinator), + with {:ok, base_slugs} <- base_slugs(base_projects_selector), + {:ok, included_slugs} <- included_slugs_by_filters(filters, filters_combinator), included_slugs = intersect_with_base_slugs(included_slugs, base_slugs), included_slugs = remove_hidden_slugs(included_slugs), {:ok, ordered_slugs} <- ordered_slugs_by_order_by(order_by, included_slugs) do @@ -197,13 +196,13 @@ defmodule Sanbase.Project.ListSelector do end end - defp base_slugs(:all), do: :all + defp base_slugs(:all), do: {:ok, :all} - defp base_slugs(args_list) do - Enum.flat_map(args_list, fn args -> + defp base_slugs(args_list) when is_list(args_list) do + Enum.reduce_while(args_list, {:ok, []}, fn args, {:ok, acc} -> case get_base_slugs(args) do - {:ok, slugs} -> slugs - {:error, error} -> raise(error) + {:ok, slugs} -> {:cont, {:ok, slugs ++ acc}} + {:error, error} -> {:halt, {:error, error}} end end) end @@ -211,7 +210,10 @@ defmodule Sanbase.Project.ListSelector do defp get_base_slugs(%{watchlist_id: id} = map) do detect_cycles!(map) - id |> Sanbase.UserList.by_id!([]) |> Sanbase.UserList.get_slugs() + case Sanbase.UserList.by_id(id, []) do + {:ok, watchlist} -> Sanbase.UserList.get_slugs(watchlist) + {:error, error} -> {:error, error} + end end defp get_base_slugs(%{watchlist_slug: slug} = map) do