Skip to content

Commit ddc3bc1

Browse files
committed
Add mode filtering and display dynamic status
1 parent bf96a4d commit ddc3bc1

File tree

5 files changed

+51
-29
lines changed

5 files changed

+51
-29
lines changed

lib/oban/web/components/icons.ex

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,6 @@ defmodule Oban.Web.Components.Icons do
66
attr :rest, :global,
77
default: %{
88
"aria-hidden": "true",
9-
class: "w-4 h-4",
10-
fill: "currentColor",
11-
viewBox: "0 0 16 16"
12-
}
13-
14-
slot :inner_block, required: true
15-
16-
defp svg_mini(assigns) do
17-
~H"""
18-
<svg {@rest}>
19-
{render_slot(@inner_block)}
20-
</svg>
21-
"""
22-
end
23-
24-
attr :rest, :global,
25-
default: %{
269
"stroke-width": "1.5",
2710
class: "w-6 h-6",
2811
fill: "none",

lib/oban/web/live/queues/table_component.ex

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,42 @@ defmodule Oban.Web.Queues.TableComponent do
108108
{started_at(@queue)}
109109
</span>
110110
111-
<div class="w-20 pr-3 flex justify-end items-center space-x-1">
111+
<div class="w-20 pr-3 flex justify-center items-center space-x-1">
112+
<Icons.globe
113+
:if={Queue.global_limit?(@queue)}
114+
class="w-5 h-5"
115+
data-title="Global limit"
116+
id={"#{@queue.name}-has-global-limit"}
117+
phx-hook="Tippy"
118+
rel="has-global-limit"
119+
/>
120+
<Icons.arrow_trending_down
121+
:if={Queue.rate_limit?(@queue)}
122+
class="w-5 h-5"
123+
data-title="Rate limit"
124+
id={"#{@queue.name}-has-rate-limit"}
125+
phx-hook="Tippy"
126+
rel="has-rate-limit"
127+
/>
112128
<Icons.pause_circle
113129
:if={Queue.all_paused?(@queue)}
114-
class="w-4 h-4"
130+
class="w-5 h-5"
115131
data-title="All paused"
116132
id={"#{@queue.name}-is-paused"}
117133
phx-hook="Tippy"
118134
rel="is-paused"
119135
/>
120136
<Icons.play_pause_circle
121137
:if={Queue.any_paused?(@queue) and not Queue.all_paused?(@queue)}
122-
class="w-4 h-4"
138+
class="w-5 h-5"
123139
data-title="Some paused"
124140
id={"#{@queue.name}-is-some-paused"}
125141
phx-hook="Tippy"
126142
rel="has-some-paused"
127143
/>
128144
<Icons.power
129145
:if={Queue.terminating?(@queue)}
130-
class="w-4 h-4"
146+
class="w-5 h-5"
131147
data-title="Terminating"
132148
id={"#{@queue.name}-is-terminating"}
133149
phx-hook="Tippy"

lib/oban/web/pages/crons_page.ex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Oban.Web.CronsPage do
55

66
alias Oban.Web.{Cron, CronQuery, Page, SearchComponent, SortComponent}
77

8-
@known_params ~w(sort_by sort_dir workers states)
8+
@known_params ~w(modes sort_by sort_dir states workers)
99

1010
@impl Phoenix.LiveComponent
1111
def render(assigns) do
@@ -127,9 +127,16 @@ defmodule Oban.Web.CronsPage do
127127
</span>
128128
129129
<div class="w-20 pr-3 flex justify-end items-center space-x-1">
130+
<Icons.sparkles
131+
:if={@cron.dynamic?}
132+
id={"cron-dynamic-icon-#{@cron.name}"}
133+
class="w-5 h-5"
134+
phx-hook="Tippy"
135+
data-title="Dynamic cron"
136+
/>
137+
130138
<span
131139
id={"cron-state-icon-#{@cron.name}"}
132-
class="py-1.5 px-2 text-xs"
133140
phx-hook="Tippy"
134141
data-title={state_title(@cron)}
135142
>
@@ -143,6 +150,7 @@ defmodule Oban.Web.CronsPage do
143150
end
144151

145152
attr :state, :string, required: true
153+
attr :rest, :global
146154

147155
defp state_icon(assigns) do
148156
~H"""

lib/oban/web/queries/cron_query.ex

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ defmodule Oban.Web.CronQuery do
1111

1212
@suggest_qualifier [
1313
{"workers:", "cron worker name", "workers:MyApp.Worker"},
14+
{"modes:", "cron mode (static/dynamic)", "modes:static"},
1415
{"states:", "last execution state", "states:completed"}
1516
]
1617

@@ -25,11 +26,16 @@ defmodule Oban.Web.CronQuery do
2526
{"unknown", "no previous jobs available", "unknown"}
2627
]
2728

29+
@suggest_mode [
30+
{"static", "regular cron job", "static"},
31+
{"dynamic", "dynamic cron job", "dynamic"}
32+
]
33+
2834
@known_qualifiers MapSet.new(@suggest_qualifier, fn {qualifier, _, _} -> qualifier end)
2935

3036
# Searching
3137

32-
def filterable, do: ~w(workers states)a
38+
def filterable, do: ~w(workers states modes)a
3339

3440
def parse(terms) when is_binary(terms) do
3541
Search.parse(terms, &parse_term/1)
@@ -47,6 +53,7 @@ defmodule Oban.Web.CronQuery do
4753
last ->
4854
case String.split(last, ":", parts: 2) do
4955
["workers", frag] -> suggest_workers(frag, conf)
56+
["modes", frag] -> suggest_static(frag, @suggest_mode)
5057
["states", frag] -> suggest_static(frag, @suggest_state)
5158
[frag] -> suggest_static(frag, @suggest_qualifier)
5259
_ -> []
@@ -98,6 +105,10 @@ defmodule Oban.Web.CronQuery do
98105
{:states, parsed}
99106
end
100107

108+
defp parse_term("modes:" <> modes) do
109+
{:modes, String.split(modes, ",")}
110+
end
111+
101112
defp parse_term(_term), do: {:none, ""}
102113

103114
# Querying
@@ -146,8 +157,8 @@ defmodule Oban.Web.CronQuery do
146157
opts: opts,
147158
dynamic?: dynamic?,
148159
next_at: next_at(expr),
149-
last_at: last_at(history, worker),
150-
last_state: get_in(history, [worker, :state])
160+
last_at: last_at(history, name),
161+
last_state: get_in(history, [name, :state])
151162
]
152163

153164
struct!(Cron, fields)
@@ -158,13 +169,13 @@ defmodule Oban.Web.CronQuery do
158169

159170
query =
160171
from(
161-
f in fragment("jsonb_array_elements(?)", ^names),
172+
f in fragment("jsonb_array_elements_text(?)", ^names),
162173
as: :list,
163174
inner_lateral_join:
164175
j in subquery(
165176
Job
166177
|> select(~w(state attempted_at cancelled_at completed_at discarded_at scheduled_at)a)
167-
|> where([j], j.meta["cron_name"] == parent_as(:list).value)
178+
|> where([j], fragment("? @> jsonb_build_object('cron_name', ?)", j.meta, parent_as(:list).value))
168179
|> order_by(desc: :id)
169180
|> limit(1)
170181
),
@@ -235,4 +246,8 @@ defmodule Oban.Web.CronQuery do
235246

236247
defp filter(cron, {:workers, workers}), do: cron.worker in workers
237248
defp filter(cron, {:states, states}), do: cron.last_state in states
249+
250+
defp filter(cron, {:modes, modes}) do
251+
if(cron.dynamic?, do: "dynamic", else: "static") in modes
252+
end
238253
end

lib/oban/web/queries/queue_query.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule Oban.Web.QueueQuery do
77
@suggest_qualifier [
88
{"nodes:", "host name", "nodes:machine@somehost"},
99
{"modes:", "a concurrency mode such as global", "global"},
10-
{"stats:", "a status such as paused, global, etc.", "paused"}
10+
{"stats:", "a status such as paused or terminating", "paused"}
1111
]
1212

1313
@suggest_mode [

0 commit comments

Comments
 (0)