forked from akira/exq_ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request akira#124 from akira/exq_scheduler
add support for exq_scheduler
- Loading branch information
Showing
15 changed files
with
224 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
defmodule ExqUIWeb.RecurringLive.Index do | ||
@moduledoc false | ||
use ExqUIWeb, :live_view | ||
@compile {:no_warn_undefined, [ExqScheduler]} | ||
|
||
@impl true | ||
def mount(_params, _session, socket) do | ||
{:ok, assign(socket, schedules_details())} | ||
end | ||
|
||
@impl true | ||
def handle_event("enqueue_now", %{"name" => name}, socket) do | ||
:ok = ExqScheduler.enqueue_now(scheduler(), String.to_atom(name)) | ||
{:noreply, assign(socket, schedules_details())} | ||
end | ||
|
||
@impl true | ||
def handle_event( | ||
"active", | ||
%{"active" => %{"name" => name, "enabled" => enabled}, "_target" => ["active", "toggle"]}, | ||
socket | ||
) do | ||
case enabled do | ||
"false" -> :ok = ExqScheduler.disable(scheduler(), String.to_atom(name)) | ||
"true" -> :ok = ExqScheduler.enable(scheduler(), String.to_atom(name)) | ||
end | ||
|
||
{:noreply, assign(socket, schedules_details())} | ||
end | ||
|
||
@impl true | ||
def handle_event("active", _, socket) do | ||
{:noreply, socket} | ||
end | ||
|
||
defp schedules_details() do | ||
schedules = ExqScheduler.schedules(scheduler()) | ||
%{items: schedules} | ||
end | ||
|
||
defp scheduler do | ||
Application.get_env(:exq_ui, :exq_scheduler_name, ExqScheduler) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<%= live_component ExqUIWeb.StatsComponent, id: "stats" %> | ||
|
||
<div> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<table class="table table-bordered"> | ||
<thead> | ||
<tr> | ||
<th scope="col">Active</th> | ||
<th scope="col">Name</th> | ||
<th scope="col">Description</th> | ||
<th scope="col">Cron</th> | ||
<th scope="col">Timezone</th> | ||
<th scope="col">Last Time</th> | ||
<th scope="col">Next Time</th> | ||
<th scope="col">Queue</th> | ||
<th scope="col">Module</th> | ||
<th scope="col">Arguments</th> | ||
<th scope="col">Action</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<%= for item <- @items do %> | ||
<tr> | ||
<td> | ||
<%= form_for :active, "#", [id: "schedule-#{item.schedule.name}", phx_change: :active, class: "mb-0 form-check form-switch form-check-inline", style: "margin: auto;display: flex;justify-content: center"], fn f -> %> | ||
<%= hidden_input(f, :name, value: item.schedule.name) %> | ||
<%= hidden_input(f, :enabled, value: !item.schedule.schedule_opts.enabled) %> | ||
<%= checkbox(f, :toggle, value: item.schedule.schedule_opts.enabled, class: "form-check-input", role: "switch", title: "disable") %> | ||
<% end %> | ||
</td> | ||
<td><%= item.schedule.name %></td> | ||
<td class="text-break"><%= item.schedule.description %></td> | ||
<td class="text-nowrap"><%= item.cron %></td> | ||
<td><%= item.schedule.timezone %></td> | ||
<td class="text-nowrap"><%= human_time(item.last_run) %></td> | ||
<td class="text-nowrap" style={!item.schedule.schedule_opts.enabled && "text-decoration: line-through"} ><%= human_time(item.next_run) %></td> | ||
<td><%= item.schedule.job.queue %></td> | ||
<td><%= item.schedule.job.class %></td> | ||
<td class="text-break"><%= inspect(item.schedule.job.args) %></td> | ||
<td class="text-nowrap"><%= link "Enqueue Now", class: "btn btn-danger btn-sm", to: "#", phx_click: "enqueue_now", phx_value_name: item.schedule.name %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.