Skip to content

Commit

Permalink
Merge branch 'master' into fix-mox-errors-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tspenov authored Nov 22, 2024
2 parents 9fc0063 + 870c7a9 commit a6c183d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 28 deletions.
21 changes: 13 additions & 8 deletions lib/sanbase/alerts/alert.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 11 additions & 11 deletions lib/sanbase/application/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
20 changes: 11 additions & 9 deletions lib/sanbase/project/list/selector/project_list_selector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -197,21 +196,24 @@ 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

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
Expand Down

0 comments on commit a6c183d

Please sign in to comment.