Skip to content

Commit

Permalink
Reorganize Cron dashboard screen; add jobs drill-drown and enqueue no…
Browse files Browse the repository at this point in the history
…w action (#436)

- Creates more space by putting job properties within a collapsible element.
- Moves `ActiveJobJob` class out of the engine and into `lib`
  • Loading branch information
bensheldon authored Oct 29, 2021
1 parent 5df2c05 commit a0da08a
Show file tree
Hide file tree
Showing 31 changed files with 346 additions and 151 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ inherit_mode:

AllCops:
TargetRubyVersion: 2.5
TargetRailsVersion: 5.2
DisplayCopNames: true
DisplayStyleGuide: true
Include:
Expand Down
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ GEM
mixlib-shellout
memory_profiler (1.0.0)
method_source (1.0.0)
mini_mime (1.1.1)
mini_mime (1.1.2)
mini_portile2 (2.6.1)
minitest (5.14.4)
mixlib-cli (2.1.8)
Expand All @@ -231,10 +231,10 @@ GEM
multipart-post (2.1.1)
nio4r (2.5.8)
nio4r (2.5.8-java)
nokogiri (1.12.4)
nokogiri (1.12.5)
mini_portile2 (~> 2.6.1)
racc (~> 1.4)
nokogiri (1.12.4-java)
nokogiri (1.12.5-java)
racc (~> 1.4)
octokit (4.21.0)
faraday (>= 0.9)
Expand Down Expand Up @@ -269,8 +269,8 @@ GEM
puma (5.5.0-java)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.5.2)
racc (1.5.2-java)
racc (1.6.0)
racc (1.6.0-java)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
Expand Down Expand Up @@ -394,7 +394,7 @@ DEPENDENCIES
activerecord-jdbcpostgresql-adapter
appraisal!
benchmark-ips
capybara
capybara (~> 3.35.0)
database_cleaner
dotenv
erb_lint (>= 0.0.35)
Expand Down
19 changes: 19 additions & 0 deletions engine/app/controllers/good_job/cron_entries_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true
module GoodJob
class CronEntriesController < GoodJob::BaseController
def index
@cron_entries = CronEntry.all
end

def show
@cron_entry = CronEntry.find(params[:id])
@jobs_filter = JobsFilter.new(params, @cron_entry.jobs)
end

def enqueue
@cron_entry = CronEntry.find(params[:id])
@cron_entry.enqueue(Time.current)
redirect_back(fallback_location: cron_entries_path, notice: "Cron entry has been enqueued.")
end
end
end
9 changes: 0 additions & 9 deletions engine/app/controllers/good_job/cron_schedules_controller.rb

This file was deleted.

11 changes: 6 additions & 5 deletions engine/app/filters/good_job/base_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ module GoodJob
class BaseFilter
DEFAULT_LIMIT = 25

attr_accessor :params
attr_accessor :params, :base_query

def initialize(params)
def initialize(params, base_query = nil)
@params = params
@base_query = base_query || default_base_query
end

def records
Expand All @@ -24,13 +25,13 @@ def last

def job_classes
base_query.group("serialized_params->>'job_class'").count
.sort_by { |name, _count| name }
.sort_by { |name, _count| name.to_s }
.to_h
end

def queues
base_query.group(:queue_name).count
.sort_by { |name, _count| name }
.sort_by { |name, _count| name.to_s }
.to_h
end

Expand Down Expand Up @@ -94,7 +95,7 @@ def chart_data

private

def base_query
def default_base_query
raise NotImplementedError
end

Expand Down
2 changes: 1 addition & 1 deletion engine/app/filters/good_job/executions_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def states

private

def base_query
def default_base_query
GoodJob::Execution.all
end

Expand Down
2 changes: 1 addition & 1 deletion engine/app/filters/good_job/jobs_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def states

private

def base_query
def default_base_query
GoodJob::ActiveJobJob.all
end

Expand Down
51 changes: 51 additions & 0 deletions engine/app/views/good_job/cron_entries/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<% if @cron_entries.present? %>
<div class="card my-3">
<div class="table-responsive">
<table class="table card-table table-bordered table-hover table-sm mb-0">
<thead>
<th>Key</th>
<th>Schedule</th>
<th>
Properties
<%= tag.button "Toggle", type: "button", class: "btn btn-sm btn-outline-primary", role: "button",
data: { bs_toggle: "collapse", bs_target: ".cron-entry-properties" },
aria: { expanded: false, controls: @cron_entries.map { |cron_entry| "##{dom_id(cron_entry, 'properties')}" }.join(" ") }
%>
</th>
<th>Description</th>
<th>Next scheduled</th>
<th>Last run</th>
<th>Actions</th>
</thead>
<tbody>
<% @cron_entries.each do |cron_entry| %>
<tr id="<%= dom_id(cron_entry) %>">
<td class="font-monospace"><%= cron_entry.key %></td>
<td class="font-monospace"><%= cron_entry.cron %></td>
<td>
<%= tag.button("Preview", type: "button", class: "btn btn-sm btn-outline-primary", role: "button",
data: { bs_toggle: "collapse", bs_target: "##{dom_id(cron_entry, 'properties')}" },
aria: { expanded: false, controls: dom_id(cron_entry, 'properties') }) %>
<%= tag.pre(JSON.pretty_generate(cron_entry.display_properties), id: dom_id(cron_entry, 'properties'), class: "collapse cron-entry-properties") %>
</td>
<td><%= cron_entry.description %></td>
<td><%= cron_entry.next_at %></td>
<td>
<% if cron_entry.last_job.present? %>
<%= link_to cron_entry.last_at, cron_entry_path(cron_entry), title: "Job #{cron_entry.last_job.id}" %>
<% end %>
</td>
<td>
<%= button_to enqueue_cron_entry_path(cron_entry.id), method: :post, class: "btn btn-sm btn-outline-primary", form_class: "d-inline-block", aria: { label: "Run cron entry now" }, title: "Run cron entry now", data: { confirm: "Confirm run cron entry now" } do %>
<%= render "good_job/shared/icons/play" %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
<% else %>
<em>No cron schedules present.</em>
<% end %>
4 changes: 4 additions & 0 deletions engine/app/views/good_job/cron_entries/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h1 class="mb-3">Cron Entry Key: <code><%= @cron_entry.id %></code></h1>

<%= render 'good_job/shared/filter', filter: @jobs_filter %>
<%= render 'good_job/jobs/table', jobs: @jobs_filter.records %>
72 changes: 0 additions & 72 deletions engine/app/views/good_job/cron_schedules/index.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion engine/app/views/good_job/executions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<%= render 'good_job/shared/filter', filter: @filter %>
<% if @filter.records.present? %>
<%= render 'good_job/shared/executions_table', executions: @filter.records %>
<%= render 'good_job/executions/table', executions: @filter.records %>

<nav aria-label="Job pagination" class="mt-3">
<ul class="pagination">
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion engine/app/views/good_job/jobs/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<%= render 'good_job/shared/filter', filter: @filter %>
<% if @filter.records.present? %>
<%= render 'good_job/shared/jobs_table', jobs: @filter.records %>
<%= render 'good_job/jobs/table', jobs: @filter.records %>
<nav aria-label="Job pagination" class="mt-3">
<ul class="pagination">
<li class="page-item">
Expand Down
4 changes: 2 additions & 2 deletions engine/app/views/good_job/jobs/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<h1>ActiveJob ID: <code><%= @executions.first.id %></code></h1>
<h1 class="mb-3">ActiveJob ID: <code><%= @executions.first.id %></code></h1>

<%= render 'good_job/shared/executions_table', executions: @executions %>
<%= render 'good_job/executions/table', executions: @executions %>
19 changes: 9 additions & 10 deletions engine/app/views/good_job/shared/_filter.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<div class='card mb-2'>
<div class='card-body d-flex flex-wrap'>

<div class='me-4'>
<small>Filter by job class</small>
<br>
<% @filter.job_classes.each do |name, count| %>
<% filter.job_classes.each do |name, count| %>
<% if params[:job_class] == name %>
<%= link_to(@filter.to_params(job_class: nil), class: 'btn btn-sm btn-outline-secondary active', role: "button", "aria-pressed": true) do %>
<%= link_to(filter.to_params(job_class: nil), class: 'btn btn-sm btn-outline-secondary active', role: "button", "aria-pressed": true) do %>
<%= name %> (<%= count %>)
<% end %>
<% else %>
<%= link_to(@filter.to_params(job_class: name), class: 'btn btn-sm btn-outline-secondary', role: "button") do %>
<%= link_to(filter.to_params(job_class: name), class: 'btn btn-sm btn-outline-secondary', role: "button") do %>
<%= name %> (<%= count %>)
<% end %>
<% end %>
Expand All @@ -20,13 +19,13 @@
<div class='me-4'>
<small>Filter by state</small>
<br>
<% @filter.states.each do |name, count| %>
<% filter.states.each do |name, count| %>
<% if params[:state] == name %>
<%= link_to(@filter.to_params(state: nil), class: 'btn btn-sm btn-outline-secondary active', role: "button", "aria-pressed": true) do %>
<%= link_to(filter.to_params(state: nil), class: 'btn btn-sm btn-outline-secondary active', role: "button", "aria-pressed": true) do %>
<%= name %> (<%= count %>)
<% end %>
<% else %>
<%= link_to(@filter.to_params(state: name), class: 'btn btn-sm btn-outline-secondary', role: "button") do %>
<%= link_to(filter.to_params(state: name), class: 'btn btn-sm btn-outline-secondary', role: "button") do %>
<%= name %> (<%= count %>)
<% end %>
<% end %>
Expand All @@ -36,13 +35,13 @@
<div>
<small>Filter by queue</small>
<br>
<% @filter.queues.each do |name, count| %>
<% filter.queues.each do |name, count| %>
<% if params[:queue_name] == name %>
<%= link_to(@filter.to_params(queue_name: nil), class: 'btn btn-sm btn-outline-secondary active', role: "button", "aria-pressed": true) do %>
<%= link_to(filter.to_params(queue_name: nil), class: 'btn btn-sm btn-outline-secondary active', role: "button", "aria-pressed": true) do %>
<%= name %> (<%= count %>)
<% end %>
<% else %>
<%= link_to(@filter.to_params(queue_name: name), class: 'btn btn-sm btn-outline-secondary', role: "button") do %>
<%= link_to(filter.to_params(queue_name: name), class: 'btn btn-sm btn-outline-secondary', role: "button") do %>
<%= name %> (<%= count %>)
<% end %>
<% end %>
Expand Down
4 changes: 4 additions & 0 deletions engine/app/views/good_job/shared/icons/_play.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- https://icons.getbootstrap.com/icons/play/ -->
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-play" viewBox="0 0 16 16">
<path d="M10.804 8 5 4.633v6.734L10.804 8zm.792-.696a.802.802 0 0 1 0 1.392l-6.363 3.692C4.713 12.69 4 12.345 4 11.692V4.308c0-.653.713-.998 1.233-.696l6.363 3.692z" />
</svg>
2 changes: 1 addition & 1 deletion engine/app/views/layouts/good_job/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<%= link_to "All Jobs", jobs_path, class: ["nav-link", ("active" if current_page?(jobs_path))] %>
</li>
<li class="nav-item">
<%= link_to "Cron Schedules", cron_schedules_path, class: ["nav-link", ("active" if current_page?(cron_schedules_path))] %>
<%= link_to "Cron Schedules", cron_entries_path, class: ["nav-link", ("active" if current_page?(cron_entries_path))] %>
</li>
<li class="nav-item">
<div class="nav-link">
Expand Down
8 changes: 7 additions & 1 deletion engine/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# frozen_string_literal: true
GoodJob::Engine.routes.draw do
root to: 'executions#index'
resources :cron_schedules, only: %i[index]

resources :cron_entries, only: %i[index show] do
member do
post :enqueue
end
end

resources :jobs, only: %i[index show] do
member do
put :discard
Expand Down
2 changes: 1 addition & 1 deletion good_job.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "zeitwerk", ">= 2.0"

spec.add_development_dependency "benchmark-ips"
spec.add_development_dependency "capybara"
spec.add_development_dependency "capybara", "~> 3.35.0" # Capybara 3.36 requires Ruby 2.6+, which is not compatible with JRuby 9.2 (MRI 2.5 compatible)
spec.add_development_dependency "database_cleaner"
spec.add_development_dependency "dotenv"
spec.add_development_dependency "foreman"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/good_job/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def enable_cron
alias enable_cron? enable_cron

def cron
env_cron = JSON.parse(ENV['GOOD_JOB_CRON']) if ENV['GOOD_JOB_CRON'].present?
env_cron = JSON.parse(ENV['GOOD_JOB_CRON'], symbolize_names: true) if ENV['GOOD_JOB_CRON'].present?

options[:cron] ||
rails_config[:cron] ||
Expand Down
Loading

0 comments on commit a0da08a

Please sign in to comment.