defmodule Oban.Web.Workflows.TableComponent do use Oban.Web, :live_component import Oban.Web.Helpers, only: [integer_to_estimate: 1, oban_path: 1] alias Oban.Web.Timing @impl Phoenix.LiveComponent def render(assigns) do ~H"""

No workflows

Workflows coordinate jobs with dependencies. They'll appear here once jobs with workflow metadata are enqueued.

""" end attr :label, :string, required: true attr :class, :string, default: "" defp header(assigns) do ~H""" {@label} """ end attr :workflow, :map, required: true defp workflow_row(assigns) do ~H"""
  • <.link patch={oban_path([:workflows, @workflow.id])} class="flex items-center hover:bg-gray-50 dark:hover:bg-gray-950/30" >
    {@workflow.display_name}
    {queue}
    <.progress_bar workflow={@workflow} /> <.activity_counts workflow={@workflow} /> <.format_duration workflow={@workflow} /> <.started_at workflow={@workflow} />
    <.status_indicator id={@workflow.id} state={@workflow.state} />
  • """ end attr :workflow, :map, required: true defp progress_bar(assigns) do activity = assigns.workflow.activity total = assigns.workflow.total finished = activity.finished percent = if total > 0, do: min(round(finished / total * 100), 100), else: 0 assigns = assign(assigns, finished: finished, total: total, percent: percent) ~H"""
    {@finished}/{@total}
    """ end attr :workflow, :map, required: true defp activity_counts(assigns) do activity = assigns.workflow.activity id = assigns.workflow.id assigns = assign(assigns, id: id, suspended: activity.suspended, pending: activity.pending, executing: activity.executing, finished: activity.finished ) ~H"""
    <.state_count id={"#{@id}-susp"} count={@suspended} color="gray" title="Suspended" /> <.state_count id={"#{@id}-pend"} count={@pending} color="blue" title="Pending" /> <.state_count id={"#{@id}-exec"} count={@executing} color="emerald" title="Executing" /> <.state_count id={"#{@id}-fin"} count={@finished} color="cyan" title="Finished" />
    """ end attr :id, :string, required: true attr :count, :integer, required: true attr :color, :string, required: true attr :title, :string, required: true defp state_count(assigns) do bg_class = case {assigns.count, assigns.color} do {0, _} -> "bg-gray-300 dark:bg-gray-600" {_, "gray"} -> "bg-gray-400" {_, "blue"} -> "bg-blue-400" {_, "emerald"} -> "bg-emerald-400" {_, "cyan"} -> "bg-cyan-400" end assigns = assign(assigns, bg_class: bg_class) ~H""" {integer_to_estimate(@count)} """ end attr :workflow, :map, required: true defp started_at(assigns) do activity = assigns.workflow.activity executed? = activity.executing + activity.finished > 0 started = if executed?, do: assigns.workflow.started_at assigns = assign(assigns, started: started) ~H""" - - """ end attr :workflow, :map, required: true defp format_duration(assigns) do wf = assigns.workflow executing? = wf.state == :executing started? = not is_nil(wf.started_at) duration = if wf.started_at && wf.completed_at do DateTime.diff(wf.completed_at, wf.started_at, :millisecond) end formatted = if is_nil(duration) or duration <= 0 do "-" else duration |> div(1000) |> Timing.to_duration() end assigns = assign(assigns, executing?: executing?, started?: started?, formatted: formatted, started_at: wf.started_at ) ~H""" - {@formatted} """ end attr :id, :string, required: true attr :state, :atom, required: true defp status_indicator(assigns) do ~H""" <%= case @state do %> <% :executing -> %> <% :completed -> %> <% :cancelled -> %> <% :discarded -> %> <% _ -> %> <% end %> """ end defp status_title(:executing), do: "Executing" defp status_title(:completed), do: "Completed" defp status_title(:cancelled), do: "Cancelled" defp status_title(:discarded), do: "Discarded" defp status_title(_), do: "Unknown" end