bdd181425b
Docker Compose project with automated Playwright benchmarks comparing django-liveview 2.2.0 against Phoenix LiveView 1.0 across 6 scenarios.
54 lines
1.2 KiB
Elixir
54 lines
1.2 KiB
Elixir
defmodule Benchmark.Alerts do
|
|
import Ecto.Query
|
|
alias Benchmark.{Repo, Alert}
|
|
|
|
@types ~w(INFO WARNING CRITICAL)
|
|
@descriptions [
|
|
"CPU usage above 90%",
|
|
"Memory leak detected in worker",
|
|
"Disk space below 10%",
|
|
"Network timeout on upstream",
|
|
"Service unreachable: auth",
|
|
"Database slow query detected",
|
|
"HTTP 5xx rate spike",
|
|
"SSL certificate expiring soon",
|
|
"Replica lag too high",
|
|
"Queue backlog growing"
|
|
]
|
|
|
|
def list_alerts do
|
|
Repo.all(from a in Alert, order_by: [desc: a.id])
|
|
end
|
|
|
|
def search_alerts(""), do: list_alerts()
|
|
|
|
def search_alerts(query) do
|
|
pattern = "%#{query}%"
|
|
Repo.all(from a in Alert, where: ilike(a.description, ^pattern), order_by: [desc: a.id])
|
|
end
|
|
|
|
def create_random_alert do
|
|
%Alert{}
|
|
|> Alert.changeset(%{
|
|
alert_type: Enum.random(@types),
|
|
description: Enum.random(@descriptions)
|
|
})
|
|
|> Repo.insert()
|
|
end
|
|
|
|
def create_alerts(count) do
|
|
Enum.each(1..count, fn _ -> create_random_alert() end)
|
|
end
|
|
|
|
def delete_alert(id) do
|
|
case Repo.get(Alert, id) do
|
|
nil -> {:error, :not_found}
|
|
alert -> Repo.delete(alert)
|
|
end
|
|
end
|
|
|
|
def clear_all do
|
|
Repo.delete_all(Alert)
|
|
end
|
|
end
|