diff --git a/services/bright/config/config.exs b/services/bright/config/config.exs index e52d3ac..5d181f2 100644 --- a/services/bright/config/config.exs +++ b/services/bright/config/config.exs @@ -23,14 +23,14 @@ config :bright, BrightWeb.Endpoint, live_view: [signing_salt: "JGNufzrG"] -config :bright, Oban, - engine: Oban.Engines.Basic, - queues: [default: 10], - repo: Bright.Repo, - plugins: [ - {Oban.Plugins.Pruner, max_age: 60 * 60 * 24 * 7}, - {Oban.Plugins.Lifeline, rescue_after: :timer.minutes(30)} - ] +# config :bright, Oban, +# engine: Oban.Engines.Basic, +# queues: [default: 10], +# repo: Bright.Repo, +# plugins: [ +# {Oban.Plugins.Pruner, max_age: 60 * 60 * 24 * 7}, +# {Oban.Plugins.Lifeline, rescue_after: :timer.minutes(30)} +# ] # Configures the mailer diff --git a/services/bright/lib/bright/application.ex b/services/bright/lib/bright/application.ex index 6678c5e..3e7429f 100644 --- a/services/bright/lib/bright/application.ex +++ b/services/bright/lib/bright/application.ex @@ -7,7 +7,7 @@ defmodule Bright.Application do @impl true def start(_type, _args) do - Oban.Telemetry.attach_default_logger(level: :debug) + # Oban.Telemetry.attach_default_logger(level: :debug) children = [ BrightWeb.Telemetry, Bright.Repo, @@ -15,7 +15,7 @@ defmodule Bright.Application do {Phoenix.PubSub, name: Bright.PubSub}, # Start the Finch HTTP client for sending emails {Finch, name: Bright.Finch}, - {Oban, Application.fetch_env!(:bright, Oban)}, + # {Oban, Application.fetch_env!(:bright, Oban)}, # Start a worker by calling: Bright.Worker.start_link(arg) # {Bright.Worker, arg}, # Start to serve requests, typically the last entry diff --git a/services/bright/lib/bright_web/router.ex b/services/bright/lib/bright_web/router.ex index c991da5..f318fbe 100644 --- a/services/bright/lib/bright_web/router.ex +++ b/services/bright/lib/bright_web/router.ex @@ -44,12 +44,11 @@ defmodule BrightWeb.Router do pipe_through :browser get "/", PageController, :home - resources "/products", ProductController get "/patrons", PatronController, :index get "/about", PageController, :about get "/api", PageController, :api - get "/up", PageController, :health + get "/health", PageController, :health resources "/orders", OrderController, only: [:create, :show] @@ -76,18 +75,8 @@ defmodule BrightWeb.Router do ## @todo DANGER, platforms must only be writable by admins, (unless we implement SVG sanitizing) resources "/platforms", PlatformController - live "/thermostat", ThermostatLive - - get "/hello", HelloController, :index - get "/hello/:messenger", HelloController, :show - live "/posts", PostLive.Index, :index - live "/posts/new", PostLive.Index, :new - live "/posts/:id/edit", PostLive.Index, :edit - - live "/posts/:id", PostLive.Show, :show - live "/posts/:id/show/edit", PostLive.Show, :edit end # Other scopes may use custom stacks. diff --git a/services/bright/lib/free_oban_ui.ex b/services/bright/lib/free_oban_ui.ex deleted file mode 100644 index f42070c..0000000 --- a/services/bright/lib/free_oban_ui.ex +++ /dev/null @@ -1,9 +0,0 @@ -defmodule FreeObanUi do - @moduledoc """ - FreeObanUi keeps the contexts that define your domain - and business logic. - - Contexts are also responsible for managing your data, regardless - if it comes from the database, an external API or others. - """ -end diff --git a/services/bright/lib/free_oban_ui/application.ex b/services/bright/lib/free_oban_ui/application.ex deleted file mode 100644 index 79794a2..0000000 --- a/services/bright/lib/free_oban_ui/application.ex +++ /dev/null @@ -1,37 +0,0 @@ -defmodule FreeObanUi.Application do - # See https://hexdocs.pm/elixir/Application.html - # for more information on OTP Applications - @moduledoc false - - use Application - - @impl true - def start(_type, _args) do - children = [ - FreeObanUiWeb.Telemetry, - FreeObanUi.Repo, - {DNSCluster, query: Application.get_env(:free_oban_ui, :dns_cluster_query) || :ignore}, - {Phoenix.PubSub, name: FreeObanUi.PubSub}, - # Start the Finch HTTP client for sending emails - {Finch, name: FreeObanUi.Finch}, - {Oban, Application.fetch_env!(:free_oban_ui, Oban)}, - # Start a worker by calling: FreeObanUi.Worker.start_link(arg) - # {FreeObanUi.Worker, arg}, - # Start to serve requests, typically the last entry - FreeObanUiWeb.Endpoint - ] - - # See https://hexdocs.pm/elixir/Supervisor.html - # for other strategies and supported options - opts = [strategy: :one_for_one, name: FreeObanUi.Supervisor] - Supervisor.start_link(children, opts) - end - - # Tell Phoenix to update the endpoint configuration - # whenever the application is updated. - @impl true - def config_change(changed, _new, removed) do - FreeObanUiWeb.Endpoint.config_change(changed, removed) - :ok - end -end diff --git a/services/bright/lib/free_oban_ui/mailer.ex b/services/bright/lib/free_oban_ui/mailer.ex deleted file mode 100644 index 93ef998..0000000 --- a/services/bright/lib/free_oban_ui/mailer.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule FreeObanUi.Mailer do - use Swoosh.Mailer, otp_app: :free_oban_ui -end diff --git a/services/bright/lib/free_oban_ui/repo.ex b/services/bright/lib/free_oban_ui/repo.ex deleted file mode 100644 index 61b34c9..0000000 --- a/services/bright/lib/free_oban_ui/repo.ex +++ /dev/null @@ -1,5 +0,0 @@ -defmodule FreeObanUi.Repo do - use Ecto.Repo, - otp_app: :free_oban_ui, - adapter: Ecto.Adapters.Postgres -end diff --git a/services/bright/lib/free_oban_ui_web.ex b/services/bright/lib/free_oban_ui_web.ex deleted file mode 100644 index 90108b9..0000000 --- a/services/bright/lib/free_oban_ui_web.ex +++ /dev/null @@ -1,113 +0,0 @@ -defmodule FreeObanUiWeb do - @moduledoc """ - The entrypoint for defining your web interface, such - as controllers, components, channels, and so on. - - This can be used in your application as: - - use FreeObanUiWeb, :controller - use FreeObanUiWeb, :html - - The definitions below will be executed for every controller, - component, etc, so keep them short and clean, focused - on imports, uses and aliases. - - Do NOT define functions inside the quoted expressions - below. Instead, define additional modules and import - those modules here. - """ - - def static_paths, do: ~w(assets fonts images favicon.ico robots.txt) - - def router do - quote do - use Phoenix.Router, helpers: false - - # Import common connection and controller functions to use in pipelines - import Plug.Conn - import Phoenix.Controller - import Phoenix.LiveView.Router - end - end - - def channel do - quote do - use Phoenix.Channel - end - end - - def controller do - quote do - use Phoenix.Controller, - formats: [:html, :json], - layouts: [html: FreeObanUiWeb.Layouts] - - import Plug.Conn - import FreeObanUiWeb.Gettext - - unquote(verified_routes()) - end - end - - def live_view do - quote do - use Phoenix.LiveView, - layout: {FreeObanUiWeb.Layouts, :app} - - unquote(html_helpers()) - end - end - - def live_component do - quote do - use Phoenix.LiveComponent - - unquote(html_helpers()) - end - end - - def html do - quote do - use Phoenix.Component - - # Import convenience functions from controllers - import Phoenix.Controller, - only: [get_csrf_token: 0, view_module: 1, view_template: 1] - - # Include general helpers for rendering HTML - unquote(html_helpers()) - end - end - - defp html_helpers do - quote do - # HTML escaping functionality - import Phoenix.HTML - # Core UI components and translation - import FreeObanUiWeb.CoreComponents - import FreeObanUiWeb.Gettext - - # Shortcut for generating JS commands - alias Phoenix.LiveView.JS - - # Routes generation with the ~p sigil - unquote(verified_routes()) - end - end - - def verified_routes do - quote do - use Phoenix.VerifiedRoutes, - endpoint: FreeObanUiWeb.Endpoint, - router: FreeObanUiWeb.Router, - statics: FreeObanUiWeb.static_paths() - end - end - - @doc """ - When used, dispatch to the appropriate controller/live_view/etc. - """ - defmacro __using__(which) when is_atom(which) do - apply(__MODULE__, which, []) - end -end diff --git a/services/bright/lib/free_oban_ui_web/components/core_components.ex b/services/bright/lib/free_oban_ui_web/components/core_components.ex deleted file mode 100644 index 8703fdd..0000000 --- a/services/bright/lib/free_oban_ui_web/components/core_components.ex +++ /dev/null @@ -1,676 +0,0 @@ -defmodule FreeObanUiWeb.CoreComponents do - @moduledoc """ - Provides core UI components. - - At first glance, this module may seem daunting, but its goal is to provide - core building blocks for your application, such as modals, tables, and - forms. The components consist mostly of markup and are well-documented - with doc strings and declarative assigns. You may customize and style - them in any way you want, based on your application growth and needs. - - The default components use Tailwind CSS, a utility-first CSS framework. - See the [Tailwind CSS documentation](https://tailwindcss.com) to learn - how to customize them or feel free to swap in another framework altogether. - - Icons are provided by [heroicons](https://heroicons.com). See `icon/1` for usage. - """ - use Phoenix.Component - - alias Phoenix.LiveView.JS - import FreeObanUiWeb.Gettext - - @doc """ - Renders a modal. - - ## Examples - - <.modal id="confirm-modal"> - This is a modal. - - - JS commands may be passed to the `:on_cancel` to configure - the closing/cancel event, for example: - - <.modal id="confirm" on_cancel={JS.navigate(~p"/posts")}> - This is another modal. - - - """ - attr :id, :string, required: true - attr :show, :boolean, default: false - attr :on_cancel, JS, default: %JS{} - slot :inner_block, required: true - - def modal(assigns) do - ~H""" - - """ - end - - def input(%{type: "select"} = assigns) do - ~H""" -
- <.label for={@id}><%= @label %> - - <.error :for={msg <- @errors}><%= msg %> -
- """ - end - - def input(%{type: "textarea"} = assigns) do - ~H""" -
- <.label for={@id}><%= @label %> - - <.error :for={msg <- @errors}><%= msg %> -
- """ - end - - # All other inputs text, datetime-local, url, password, etc. are handled here... - def input(assigns) do - ~H""" -
- <.label for={@id}><%= @label %> - - <.error :for={msg <- @errors}><%= msg %> -
- """ - end - - @doc """ - Renders a label. - """ - attr :for, :string, default: nil - slot :inner_block, required: true - - def label(assigns) do - ~H""" - - """ - end - - @doc """ - Generates a generic error message. - """ - slot :inner_block, required: true - - def error(assigns) do - ~H""" -

- <.icon name="hero-exclamation-circle-mini" class="mt-0.5 h-5 w-5 flex-none" /> - <%= render_slot(@inner_block) %> -

- """ - end - - @doc """ - Renders a header with title. - """ - attr :class, :string, default: nil - - slot :inner_block, required: true - slot :subtitle - slot :actions - - def header(assigns) do - ~H""" -
-
-

- <%= render_slot(@inner_block) %> -

-

- <%= render_slot(@subtitle) %> -

-
-
<%= render_slot(@actions) %>
-
- """ - end - - @doc ~S""" - Renders a table with generic styling. - - ## Examples - - <.table id="users" rows={@users}> - <:col :let={user} label="id"><%= user.id %> - <:col :let={user} label="username"><%= user.username %> - - """ - attr :id, :string, required: true - attr :rows, :list, required: true - attr :row_id, :any, default: nil, doc: "the function for generating the row id" - attr :row_click, :any, default: nil, doc: "the function for handling phx-click on each row" - - attr :row_item, :any, - default: &Function.identity/1, - doc: "the function for mapping each row before calling the :col and :action slots" - - slot :col, required: true do - attr :label, :string - end - - slot :action, doc: "the slot for showing user actions in the last table column" - - def table(assigns) do - assigns = - with %{rows: %Phoenix.LiveView.LiveStream{}} <- assigns do - assign(assigns, row_id: assigns.row_id || fn {id, _item} -> id end) - end - - ~H""" -
- - - - - - - - - - - - - -
<%= col[:label] %> - <%= gettext("Actions") %> -
-
- - - <%= render_slot(col, @row_item.(row)) %> - -
-
-
- - - <%= render_slot(action, @row_item.(row)) %> - -
-
-
- """ - end - - @doc """ - Renders a data list. - - ## Examples - - <.list> - <:item title="Title"><%= @post.title %> - <:item title="Views"><%= @post.views %> - - """ - slot :item, required: true do - attr :title, :string, required: true - end - - def list(assigns) do - ~H""" -
-
-
-
<%= item.title %>
-
<%= render_slot(item) %>
-
-
-
- """ - end - - @doc """ - Renders a back navigation link. - - ## Examples - - <.back navigate={~p"/posts"}>Back to posts - """ - attr :navigate, :any, required: true - slot :inner_block, required: true - - def back(assigns) do - ~H""" -
- <.link - navigate={@navigate} - class="text-sm font-semibold leading-6 text-zinc-900 hover:text-zinc-700" - > - <.icon name="hero-arrow-left-solid" class="h-3 w-3" /> - <%= render_slot(@inner_block) %> - -
- """ - end - - @doc """ - Renders a [Heroicon](https://heroicons.com). - - Heroicons come in three styles – outline, solid, and mini. - By default, the outline style is used, but solid and mini may - be applied by using the `-solid` and `-mini` suffix. - - You can customize the size and colors of the icons by setting - width, height, and background color classes. - - Icons are extracted from the `deps/heroicons` directory and bundled within - your compiled app.css by the plugin in your `assets/tailwind.config.js`. - - ## Examples - - <.icon name="hero-x-mark-solid" /> - <.icon name="hero-arrow-path" class="ml-1 w-3 h-3 animate-spin" /> - """ - attr :name, :string, required: true - attr :class, :string, default: nil - - def icon(%{name: "hero-" <> _} = assigns) do - ~H""" - - """ - end - - ## JS Commands - - def show(js \\ %JS{}, selector) do - JS.show(js, - to: selector, - time: 300, - transition: - {"transition-all transform ease-out duration-300", - "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95", - "opacity-100 translate-y-0 sm:scale-100"} - ) - end - - def hide(js \\ %JS{}, selector) do - JS.hide(js, - to: selector, - time: 200, - transition: - {"transition-all transform ease-in duration-200", - "opacity-100 translate-y-0 sm:scale-100", - "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"} - ) - end - - def show_modal(js \\ %JS{}, id) when is_binary(id) do - js - |> JS.show(to: "##{id}") - |> JS.show( - to: "##{id}-bg", - time: 300, - transition: {"transition-all transform ease-out duration-300", "opacity-0", "opacity-100"} - ) - |> show("##{id}-container") - |> JS.add_class("overflow-hidden", to: "body") - |> JS.focus_first(to: "##{id}-content") - end - - def hide_modal(js \\ %JS{}, id) do - js - |> JS.hide( - to: "##{id}-bg", - transition: {"transition-all transform ease-in duration-200", "opacity-100", "opacity-0"} - ) - |> hide("##{id}-container") - |> JS.hide(to: "##{id}", transition: {"block", "block", "hidden"}) - |> JS.remove_class("overflow-hidden", to: "body") - |> JS.pop_focus() - end - - @doc """ - Translates an error message using gettext. - """ - def translate_error({msg, opts}) do - # When using gettext, we typically pass the strings we want - # to translate as a static argument: - # - # # Translate the number of files with plural rules - # dngettext("errors", "1 file", "%{count} files", count) - # - # However the error messages in our forms and APIs are generated - # dynamically, so we need to translate them by calling Gettext - # with our gettext backend as first argument. Translations are - # available in the errors.po file (as we use the "errors" domain). - if count = opts[:count] do - Gettext.dngettext(FreeObanUiWeb.Gettext, "errors", msg, msg, count, opts) - else - Gettext.dgettext(FreeObanUiWeb.Gettext, "errors", msg, opts) - end - end - - @doc """ - Translates the errors for a field from a keyword list of errors. - """ - def translate_errors(errors, field) when is_list(errors) do - for {^field, {msg, opts}} <- errors, do: translate_error({msg, opts}) - end -end diff --git a/services/bright/lib/free_oban_ui_web/components/layouts.ex b/services/bright/lib/free_oban_ui_web/components/layouts.ex deleted file mode 100644 index d5aa25a..0000000 --- a/services/bright/lib/free_oban_ui_web/components/layouts.ex +++ /dev/null @@ -1,14 +0,0 @@ -defmodule FreeObanUiWeb.Layouts do - @moduledoc """ - This module holds different layouts used by your application. - - See the `layouts` directory for all templates available. - The "root" layout is a skeleton rendered as part of the - application router. The "app" layout is set as the default - layout on both `use FreeObanUiWeb, :controller` and - `use FreeObanUiWeb, :live_view`. - """ - use FreeObanUiWeb, :html - - embed_templates "layouts/*" -end diff --git a/services/bright/lib/free_oban_ui_web/components/layouts/app.html.heex b/services/bright/lib/free_oban_ui_web/components/layouts/app.html.heex deleted file mode 100644 index 5f1d238..0000000 --- a/services/bright/lib/free_oban_ui_web/components/layouts/app.html.heex +++ /dev/null @@ -1,2 +0,0 @@ -<.flash_group flash={@flash} /> -<%= @inner_content %> \ No newline at end of file diff --git a/services/bright/lib/free_oban_ui_web/components/layouts/root.html.heex b/services/bright/lib/free_oban_ui_web/components/layouts/root.html.heex deleted file mode 100644 index e633a90..0000000 --- a/services/bright/lib/free_oban_ui_web/components/layouts/root.html.heex +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - <.live_title suffix=" · Phoenix Framework"> - <%= assigns[:page_title] || "FreeObanUi" %> - - - - - - <%= @inner_content %> - - diff --git a/services/bright/lib/free_oban_ui_web/controllers/error_html.ex b/services/bright/lib/free_oban_ui_web/controllers/error_html.ex deleted file mode 100644 index 54fe5b4..0000000 --- a/services/bright/lib/free_oban_ui_web/controllers/error_html.ex +++ /dev/null @@ -1,24 +0,0 @@ -defmodule FreeObanUiWeb.ErrorHTML do - @moduledoc """ - This module is invoked by your endpoint in case of errors on HTML requests. - - See config/config.exs. - """ - use FreeObanUiWeb, :html - - # If you want to customize your error pages, - # uncomment the embed_templates/1 call below - # and add pages to the error directory: - # - # * lib/free_oban_ui_web/controllers/error_html/404.html.heex - # * lib/free_oban_ui_web/controllers/error_html/500.html.heex - # - # embed_templates "error_html/*" - - # The default is to render a plain text page based on - # the template name. For example, "404.html" becomes - # "Not Found". - def render(template, _assigns) do - Phoenix.Controller.status_message_from_template(template) - end -end diff --git a/services/bright/lib/free_oban_ui_web/controllers/error_json.ex b/services/bright/lib/free_oban_ui_web/controllers/error_json.ex deleted file mode 100644 index 5d5ba21..0000000 --- a/services/bright/lib/free_oban_ui_web/controllers/error_json.ex +++ /dev/null @@ -1,21 +0,0 @@ -defmodule FreeObanUiWeb.ErrorJSON do - @moduledoc """ - This module is invoked by your endpoint in case of errors on JSON requests. - - See config/config.exs. - """ - - # If you want to customize a particular status code, - # you may add your own clauses, such as: - # - # def render("500.json", _assigns) do - # %{errors: %{detail: "Internal Server Error"}} - # end - - # By default, Phoenix returns the status message from - # the template name. For example, "404.json" becomes - # "Not Found". - def render(template, _assigns) do - %{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}} - end -end diff --git a/services/bright/lib/free_oban_ui_web/controllers/page_controller.ex b/services/bright/lib/free_oban_ui_web/controllers/page_controller.ex deleted file mode 100644 index 3cca7d2..0000000 --- a/services/bright/lib/free_oban_ui_web/controllers/page_controller.ex +++ /dev/null @@ -1,9 +0,0 @@ -defmodule FreeObanUiWeb.PageController do - use FreeObanUiWeb, :controller - - def home(conn, _params) do - # The home page is often custom made, - # so skip the default app layout. - render(conn, :home, layout: false) - end -end diff --git a/services/bright/lib/free_oban_ui_web/controllers/page_html.ex b/services/bright/lib/free_oban_ui_web/controllers/page_html.ex deleted file mode 100644 index 646bb8c..0000000 --- a/services/bright/lib/free_oban_ui_web/controllers/page_html.ex +++ /dev/null @@ -1,10 +0,0 @@ -defmodule FreeObanUiWeb.PageHTML do - @moduledoc """ - This module contains pages rendered by PageController. - - See the `page_html` directory for all templates available. - """ - use FreeObanUiWeb, :html - - embed_templates "page_html/*" -end diff --git a/services/bright/lib/free_oban_ui_web/controllers/page_html/home.html.heex b/services/bright/lib/free_oban_ui_web/controllers/page_html/home.html.heex deleted file mode 100644 index dc1820b..0000000 --- a/services/bright/lib/free_oban_ui_web/controllers/page_html/home.html.heex +++ /dev/null @@ -1,222 +0,0 @@ -<.flash_group flash={@flash} /> - -
-
- -

- Phoenix Framework - - v<%= Application.spec(:phoenix, :vsn) %> - -

-

- Peace of mind from prototype to production. -

-

- Build rich, interactive web applications quickly, with less code and fewer moving parts. Join our growing community of developers using Phoenix to craft APIs, HTML5 apps and more, for fun or at scale. -

- -
-
diff --git a/services/bright/lib/free_oban_ui_web/endpoint.ex b/services/bright/lib/free_oban_ui_web/endpoint.ex deleted file mode 100644 index 109b149..0000000 --- a/services/bright/lib/free_oban_ui_web/endpoint.ex +++ /dev/null @@ -1,53 +0,0 @@ -defmodule FreeObanUiWeb.Endpoint do - use Phoenix.Endpoint, otp_app: :free_oban_ui - - # The session will be stored in the cookie and signed, - # this means its contents can be read but not tampered with. - # Set :encryption_salt if you would also like to encrypt it. - @session_options [ - store: :cookie, - key: "_free_oban_ui_key", - signing_salt: "O5fc1lbf", - same_site: "Lax" - ] - - socket "/live", Phoenix.LiveView.Socket, - websocket: [connect_info: [session: @session_options]], - longpoll: [connect_info: [session: @session_options]] - - # Serve at "/" the static files from "priv/static" directory. - # - # You should set gzip to true if you are running phx.digest - # when deploying your static files in production. - plug Plug.Static, - at: "/", - from: :free_oban_ui, - gzip: false, - only: FreeObanUiWeb.static_paths() - - # Code reloading can be explicitly enabled under the - # :code_reloader configuration of your endpoint. - if code_reloading? do - socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket - plug Phoenix.LiveReloader - plug Phoenix.CodeReloader - plug Phoenix.Ecto.CheckRepoStatus, otp_app: :free_oban_ui - end - - plug Phoenix.LiveDashboard.RequestLogger, - param_key: "request_logger", - cookie_key: "request_logger" - - plug Plug.RequestId - plug Plug.Telemetry, event_prefix: [:phoenix, :endpoint] - - plug Plug.Parsers, - parsers: [:urlencoded, :multipart, :json], - pass: ["*/*"], - json_decoder: Phoenix.json_library() - - plug Plug.MethodOverride - plug Plug.Head - plug Plug.Session, @session_options - plug FreeObanUiWeb.Router -end diff --git a/services/bright/lib/free_oban_ui_web/gettext.ex b/services/bright/lib/free_oban_ui_web/gettext.ex deleted file mode 100644 index 134539f..0000000 --- a/services/bright/lib/free_oban_ui_web/gettext.ex +++ /dev/null @@ -1,24 +0,0 @@ -defmodule FreeObanUiWeb.Gettext do - @moduledoc """ - A module providing Internationalization with a gettext-based API. - - By using [Gettext](https://hexdocs.pm/gettext), - your module gains a set of macros for translations, for example: - - import FreeObanUiWeb.Gettext - - # Simple translation - gettext("Here is the string to translate") - - # Plural translation - ngettext("Here is the string to translate", - "Here are the strings to translate", - 3) - - # Domain-based translation - dgettext("errors", "Here is the error message to translate") - - See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage. - """ - use Gettext, otp_app: :free_oban_ui -end diff --git a/services/bright/lib/free_oban_ui_web/live/oban_live/index.ex b/services/bright/lib/free_oban_ui_web/live/oban_live/index.ex deleted file mode 100644 index 927aef9..0000000 --- a/services/bright/lib/free_oban_ui_web/live/oban_live/index.ex +++ /dev/null @@ -1,233 +0,0 @@ -defmodule FreeObanUiWeb.ObanLive.Index do - use FreeObanUiWeb, :live_view - alias FreeObanUi.Repo - import Ecto.Query - - @impl true - def mount(params, _session, socket) do - if connected?(socket) do - :timer.send_interval(2000, self(), :update) - end - - {:ok, - socket - |> assign( - jobs: [], - job: nil, - selected_jobs: MapSet.new(), - auto_refresh: true, - page: params["page"] || "0" - ) - |> assign_params(params) - |> assign_counts() - |> fetch_jobs()} - end - - defp assign_params(socket, params) do - socket - |> assign( - state: params["state"], - queue: params["queue"], - id: params["id"], - page: params["page"] || "0" - ) - end - - @impl true - def handle_params(params, _url, socket) do - {:noreply, - socket - |> assign_params(params) - |> fetch_jobs() - |> apply_action(socket.assigns.live_action, params)} - end - - defp apply_action(socket, :index, _params) do - socket - |> assign(:page_title, "Oban Jobs") - |> assign(:job, nil) - end - - defp apply_action(socket, :show, %{"id" => id}) do - job = get_job(id) - - socket - |> assign(:page_title, "Job #{job.id}") - |> assign(:job, get_job(id)) - end - - @impl true - def handle_event("delete", %{"id" => id}, socket) do - action_job("delete", id) - - {:noreply, - socket - |> put_flash(:info, "Job ##{id} deleted") - |> redirect_back()} - end - - defp action_job(action, id) do - case action do - # Same implementation as `retry` atm. - # Alt: is to overwrite `scheduled_at` timestamp: https://elixirforum.com/t/53920/2 - "run" -> get_job(id) |> Oban.retry_job() - "retry" -> get_job(id) |> Oban.retry_job() - "cancel" -> get_job(id) |> Oban.cancel_job() - "delete" -> get_job(id) |> Repo.delete() - end - end - - @impl true - def handle_event("execute_action", %{"action" => action}, socket) do - id = socket.assigns.job.id - action_job(action, id) - - socket = - if action == "delete" do - socket - |> put_flash(:info, "Job ##{id} deleted") - |> redirect_back() - else - fetch_jobs(socket) - end - - {:noreply, socket} - end - - @impl true - def handle_event("bulk_action", %{"action" => action}, socket) do - Enum.each(socket.assigns.selected_jobs, fn id -> - action_job(action, id) - end) - - {:noreply, socket |> assign(selected_jobs: MapSet.new()) |> fetch_jobs()} - end - - @impl true - def handle_event("paginate", %{"page" => page}, socket) do - {:noreply, - push_patch(socket, - to: ~p"/oban?#{[queue: socket.assigns.queue, state: socket.assigns.state, page: page]}" - )} - end - - @impl true - def handle_event("toggle_refresh", _, socket) do - {:noreply, assign(socket, auto_refresh: !socket.assigns.auto_refresh)} - end - - @impl true - def handle_info(:update, %{assigns: %{auto_refresh: true}} = socket) do - {:noreply, fetch_jobs(socket)} - end - - @impl true - def handle_info(:update, socket), do: {:noreply, socket} - - def available_actions(state) do - case state do - "executing" -> ~w(cancel) - "scheduled" -> ~w(run cancel delete) - "retryable" -> ~w(retry cancel delete) - "cancelled" -> ~w(retry delete) - "discarded" -> ~w(retry delete) - "complete" -> ~w(retry delete) - _ -> ~w(delete) - end - end - - def back_url(assigns) do - ~p"/oban?#{[queue: assigns.queue, state: assigns.state, page: assigns.page]}" - end - - defp redirect_back(socket) do - push_patch(socket, to: back_url(socket.assigns)) - end - - defp job_stats(job) do - [ - %{title: "State", value: job.state}, - %{title: "Queue", value: job.queue}, - %{title: "Worker", value: job.worker}, - %{title: "Inserted At", value: job.inserted_at}, - %{title: "Scheduled At", value: job.scheduled_at}, - %{title: "Discarded At", value: job.discarded_at}, - %{title: "Cancelled At", value: job.cancelled_at}, - %{title: "Attempted At", value: job.attempted_at}, - %{title: "Completed At", value: job.completed_at}, - %{title: "Attempt", value: "#{job.attempt} of #{job.max_attempts}"} - ] - end - - defp assign_counts(socket) do - counts = - Oban.Job - |> group_by([j], j.state) - |> select([j], {j.state, count(j.id)}) - |> Repo.all() - |> Enum.into(%{}) - - queues = - Oban.Job - |> group_by([j], j.queue) - |> select([j], {j.queue, count(j.id)}) - |> Repo.all() - |> Enum.into(%{}) - - assign(socket, counts: counts, queues: queues) - end - - defp fetch_jobs(socket) do - # Fetch & refresh `jobs` for :index, and `job` for :show - if socket.assigns.live_action == :index do - jobs = - Oban.Job - |> filter_by_state(socket.assigns.state) - |> filter_by_queue(socket.assigns.queue) - |> order_by([j], desc: j.inserted_at) - |> paginate(socket.assigns.page) - |> Repo.all() - - assign(socket, jobs: jobs) - else - assign(socket, jobs: [], job: get_job(socket.assigns.id)) - end - end - - defp paginate(query, page) when page in [nil, ""], do: query - - defp paginate(query, page) do - per_page = 25 - page = String.to_integer(page) - offset_by = per_page * page - - query - |> limit(^per_page) - |> offset(^offset_by) - end - - defp get_job(id) when id in [nil, ""], do: nil - defp get_job(id), do: Oban.Job |> Repo.get!(id) - - defp filter_by_state(query, state) when state in [nil, ""], do: query - defp filter_by_state(query, state), do: where(query, [j], j.state == ^state) - - defp filter_by_queue(query, queue) when queue in [nil, ""], do: query - defp filter_by_queue(query, queue), do: where(query, [j], j.queue == ^queue) - - def from_now_short(now \\ DateTime.utc_now(), later) do - diff = DateTime.diff(now, later) - - cond do - diff <= -24 * 3600 -> "in #{div(-diff, 24 * 3600)}d" - diff <= -3600 -> "in #{div(-diff, 3600)}h" - diff <= -60 -> "in #{div(-diff, 60)}m" - diff <= -5 -> "in #{-diff}s" - diff <= 5 -> "now" - diff <= 60 -> "#{diff}s ago" - diff <= 3600 -> "#{div(diff, 60)} minutes ago" - diff <= 24 * 3600 -> "#{div(diff, 3600)}m ago" - true -> "#{div(diff, 24 * 3600)}d ago" - end - end -end diff --git a/services/bright/lib/free_oban_ui_web/live/oban_live/index.html.heex b/services/bright/lib/free_oban_ui_web/live/oban_live/index.html.heex deleted file mode 100644 index e3cc616..0000000 --- a/services/bright/lib/free_oban_ui_web/live/oban_live/index.html.heex +++ /dev/null @@ -1,244 +0,0 @@ -
-
-
-

States

- <%= if @state not in ["", nil] do %> - <.link patch={~p"/oban?#{[queue: @queue, state: nil]}"} class=""> - Clear - - <% end %> -
- <%= for state <- ~w(scheduled executing completed retryable cancelled discarded) do %> - <.link - patch={~p"/oban?#{[state: state, queue: @queue]}"} - class={"#{if @state == state, do: "bg-gray-200 text-gray-900 dark:bg-gray-900 dark:text-white", else: "text-gray-600 hover:bg-gray-50 hover:text-gray-900 dark:text-gray-300"} text-gray-600 hover:bg-gray-300 hover:text-gray-900 group flex items-center px-2 py-2.5 fw-500 rounded-md dark:hover:bg-gray-700 dark:hover:text-white"} - > - <%= state %> (<%= @counts[state] || 0 %>) - - <% end %> - -
-

Queues

- <%= if @queue not in ["", nil] do %> - <.link patch={~p"/oban?#{[queue: nil, state: @state]}"} class=""> - Clear - - <% end %> -
- <%= for {queue, count} <- @queues do %> - <.link - patch={~p"/oban?#{[queue: queue, state: @state]}"} - class={"#{if @queue == queue, do: "bg-gray-200 text-gray-900 dark:bg-gray-900 dark:text-white", else: "text-gray-600 hover:bg-gray-50 hover:text-gray-900 dark:text-gray-300"} text-gray-600 hover:bg-gray-300 hover:text-gray-900 group flex items-center px-2 py-2.5 fw-500 rounded-md dark:hover:bg-gray-700 dark:hover:text-white"} - > - <%= queue %> (<%= count %>) - - <% end %> -
- -
-
- <%= if @live_action == :index do %> -

Oban Jobs

- <% else %> - <.link patch={back_url(assigns)} class="text-2xl font-bold hover:text-gray-500">← Oban Jobs - <% end %> -
- -
-
- -
- <% state = if @live_action == :index, do: @state, else: @job.state %> - <% event = if @live_action == :index, do: "bulk_action", else: "execute_action" %> - <%= for action <- available_actions(state) do %> - - <% end %> -
- - <%= if @live_action == :index do %> -
-
-
- - - - - - - - - - - - - - - - - - - - <%= for job <- @jobs do %> - - - - - - - - - - - <% end %> - -
- - - ID - - Worker - - Attempt - - State - - Queue - - Inserted -
- - - - - <%= job.id %> - - <.link - class="text-blue-600 hover:text-blue-800 hover:text-underline" - patch={~p"/oban/#{job.id}?#{[queue: @queue, state: @state, page: @page]}"} - > - <%= job.worker %> - - - <%= Jason.encode!(job.args) %> - - - <%= job.attempt %> / <%= job.max_attempts %> - - - <%= job.state %> - - - - <%= job.queue %> - - - <%= from_now_short(job.inserted_at) %> -
-
-
- - -
- <%= @page %> -
- -
-
-
- <% else %> - <%= if @job do %> -
-
-

Job #<%= @job.id %>

-
- -
- <%= for stat <- job_stats(@job) do %> -
-
<%= stat.title %>
-
<%= stat.value %>
-
- <% end %> -
-
Args
-
<%= Jason.encode!(@job.args, pretty: true) %>
-
-
-
Meta
-
<%= Jason.encode!(@job.meta, pretty: true) %>
-
- -
-
Errors
-
- <%= for error <- @job.errors do %> -
- Attempt <%= error["attempt"] %> / <%= @job.max_attempts %> at <%= error["at"] %> -
-
<%= raw error["error"] %>
- <% end %> -
-
-
- -
- <% end %> - <% end %> -
-
diff --git a/services/bright/lib/free_oban_ui_web/router.ex b/services/bright/lib/free_oban_ui_web/router.ex deleted file mode 100644 index 6d10800..0000000 --- a/services/bright/lib/free_oban_ui_web/router.ex +++ /dev/null @@ -1,51 +0,0 @@ -defmodule FreeObanUiWeb.Router do - use FreeObanUiWeb, :router - - pipeline :browser do - plug :accepts, ["html"] - plug :fetch_session - plug :fetch_live_flash - plug :put_root_layout, html: {FreeObanUiWeb.Layouts, :root} - plug :protect_from_forgery - plug :put_secure_browser_headers - end - - pipeline :api do - plug :accepts, ["json"] - end - - scope "/", FreeObanUiWeb do - pipe_through :browser - - get "/", PageController, :home - end - - scope "/oban", FreeObanUiWeb do - pipe_through [:browser] - - live "/", ObanLive.Index, :index - live "/:id", ObanLive.Index, :show - end - - # Other scopes may use custom stacks. - # scope "/api", FreeObanUiWeb do - # pipe_through :api - # end - - # Enable LiveDashboard and Swoosh mailbox preview in development - if Application.compile_env(:free_oban_ui, :dev_routes) do - # If you want to use the LiveDashboard in production, you should put - # it behind authentication and allow only admins to access it. - # If your application does not have an admins-only section yet, - # you can use Plug.BasicAuth to set up some basic authentication - # as long as you are also using SSL (which you should anyway). - import Phoenix.LiveDashboard.Router - - scope "/dev" do - pipe_through :browser - - live_dashboard "/dashboard", metrics: FreeObanUiWeb.Telemetry - forward "/mailbox", Plug.Swoosh.MailboxPreview - end - end -end diff --git a/services/bright/lib/free_oban_ui_web/telemetry.ex b/services/bright/lib/free_oban_ui_web/telemetry.ex deleted file mode 100644 index df1cff6..0000000 --- a/services/bright/lib/free_oban_ui_web/telemetry.ex +++ /dev/null @@ -1,92 +0,0 @@ -defmodule FreeObanUiWeb.Telemetry do - use Supervisor - import Telemetry.Metrics - - def start_link(arg) do - Supervisor.start_link(__MODULE__, arg, name: __MODULE__) - end - - @impl true - def init(_arg) do - children = [ - # Telemetry poller will execute the given period measurements - # every 10_000ms. Learn more here: https://hexdocs.pm/telemetry_metrics - {:telemetry_poller, measurements: periodic_measurements(), period: 10_000} - # Add reporters as children of your supervision tree. - # {Telemetry.Metrics.ConsoleReporter, metrics: metrics()} - ] - - Supervisor.init(children, strategy: :one_for_one) - end - - def metrics do - [ - # Phoenix Metrics - summary("phoenix.endpoint.start.system_time", - unit: {:native, :millisecond} - ), - summary("phoenix.endpoint.stop.duration", - unit: {:native, :millisecond} - ), - summary("phoenix.router_dispatch.start.system_time", - tags: [:route], - unit: {:native, :millisecond} - ), - summary("phoenix.router_dispatch.exception.duration", - tags: [:route], - unit: {:native, :millisecond} - ), - summary("phoenix.router_dispatch.stop.duration", - tags: [:route], - unit: {:native, :millisecond} - ), - summary("phoenix.socket_connected.duration", - unit: {:native, :millisecond} - ), - summary("phoenix.channel_joined.duration", - unit: {:native, :millisecond} - ), - summary("phoenix.channel_handled_in.duration", - tags: [:event], - unit: {:native, :millisecond} - ), - - # Database Metrics - summary("free_oban_ui.repo.query.total_time", - unit: {:native, :millisecond}, - description: "The sum of the other measurements" - ), - summary("free_oban_ui.repo.query.decode_time", - unit: {:native, :millisecond}, - description: "The time spent decoding the data received from the database" - ), - summary("free_oban_ui.repo.query.query_time", - unit: {:native, :millisecond}, - description: "The time spent executing the query" - ), - summary("free_oban_ui.repo.query.queue_time", - unit: {:native, :millisecond}, - description: "The time spent waiting for a database connection" - ), - summary("free_oban_ui.repo.query.idle_time", - unit: {:native, :millisecond}, - description: - "The time the connection spent waiting before being checked out for the query" - ), - - # VM Metrics - summary("vm.memory.total", unit: {:byte, :kilobyte}), - summary("vm.total_run_queue_lengths.total"), - summary("vm.total_run_queue_lengths.cpu"), - summary("vm.total_run_queue_lengths.io") - ] - end - - defp periodic_measurements do - [ - # A module, function and arguments to be invoked periodically. - # This function must call :telemetry.execute/3 and a metric must be added above. - # {FreeObanUiWeb, :count_users, []} - ] - end -end