Skip to content

Commit

Permalink
Add dashboard for cron-style jobs (#367)
Browse files Browse the repository at this point in the history
* Add dashboard for cron-style jobs

* Rename nav item

* Apply review changes
  • Loading branch information
aried3r authored Sep 11, 2021
1 parent ecaa985 commit 7428b89
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
10 changes: 10 additions & 0 deletions engine/app/controllers/good_job/cron_schedules_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module GoodJob
class CronSchedulesController < GoodJob::BaseController
def index
configuration = GoodJob::Configuration.new({})
@cron_schedules = configuration.cron
end
end
end
28 changes: 28 additions & 0 deletions engine/app/views/good_job/cron_schedules/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<% if @cron_schedules.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>Cron Job Name</th>
<th>Configuration</th>
<th>Class</th>
<th>Description</th>
<th>Next execution</th>
</thead>
<tbody>
<% @cron_schedules.each do |job_key, job| %>
<tr>
<td class="font-monospace"><%= job_key %></td>
<td class="font-monospace"><%= job[:cron] %></td>
<td class="font-monospace"><%= job[:class] %></td>
<td><%= job[:description] %></td>
<td><%= Fugit.parse_cron(job[:cron]).next_time.to_local_time %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
<% else %>
<em>No cron jobs present.</em>
<% end %>
12 changes: 9 additions & 3 deletions engine/app/views/layouts/good_job/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto">
<li class="nav-item">
<%= link_to root_path, class: ["nav-link", ("active" if current_page?(root_path))] do %>
All jobs <span class="badge bg-secondary">More views coming soon</span>
<% end %>
<%= link_to "All Jobs", root_path, class: ["nav-link", ("active" if current_page?(root_path))] %>
</li>
<li class="nav-item">
<%= link_to "Cron Schedules", cron_schedules_path, class: ["nav-link", ("active" if current_page?(root_path))] %>
</li>
<li class="nav-item">
<div class="nav-link">
<span class="badge bg-secondary">More views coming soon</span>
</div>
</li>

<!-- Coming Soon
Expand Down
1 change: 1 addition & 0 deletions engine/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true
GoodJob::Engine.routes.draw do
root to: 'dashboards#index'
resources :cron_schedules, only: %i[index]
resources :active_jobs, only: %i[show]
resources :jobs, only: %i[destroy]

Expand Down
9 changes: 9 additions & 0 deletions spec/system/cron_schedules_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true
require 'rails_helper'

describe 'Cron Schedules', type: :system, js: true do
it 'renders successfully' do
visit '/good_job/cron_schedules'
expect(page).to have_content 'ExampleJob'
end
end

0 comments on commit 7428b89

Please sign in to comment.