diff --git a/.rubocop.yml b/.rubocop.yml index 24ed3de17..0d13e96d0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,6 +12,7 @@ inherit_mode: AllCops: TargetRubyVersion: 2.5 + TargetRailsVersion: 5.2 DisplayCopNames: true DisplayStyleGuide: true Include: diff --git a/Gemfile.lock b/Gemfile.lock index 30ee23411..a43af4fbd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -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) @@ -394,7 +394,7 @@ DEPENDENCIES activerecord-jdbcpostgresql-adapter appraisal! benchmark-ips - capybara + capybara (~> 3.35.0) database_cleaner dotenv erb_lint (>= 0.0.35) diff --git a/engine/app/controllers/good_job/cron_entries_controller.rb b/engine/app/controllers/good_job/cron_entries_controller.rb new file mode 100644 index 000000000..028f3bcb0 --- /dev/null +++ b/engine/app/controllers/good_job/cron_entries_controller.rb @@ -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 diff --git a/engine/app/controllers/good_job/cron_schedules_controller.rb b/engine/app/controllers/good_job/cron_schedules_controller.rb deleted file mode 100644 index 58488cfec..000000000 --- a/engine/app/controllers/good_job/cron_schedules_controller.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true -module GoodJob - class CronSchedulesController < GoodJob::BaseController - def index - configuration = GoodJob::Configuration.new({}) - @cron_entries = configuration.cron_entries - end - end -end diff --git a/engine/app/filters/good_job/base_filter.rb b/engine/app/filters/good_job/base_filter.rb index 860d273a0..af7295dd0 100644 --- a/engine/app/filters/good_job/base_filter.rb +++ b/engine/app/filters/good_job/base_filter.rb @@ -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 @@ -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 @@ -94,7 +95,7 @@ def chart_data private - def base_query + def default_base_query raise NotImplementedError end diff --git a/engine/app/filters/good_job/executions_filter.rb b/engine/app/filters/good_job/executions_filter.rb index f5087c614..120f370f8 100644 --- a/engine/app/filters/good_job/executions_filter.rb +++ b/engine/app/filters/good_job/executions_filter.rb @@ -12,7 +12,7 @@ def states private - def base_query + def default_base_query GoodJob::Execution.all end diff --git a/engine/app/filters/good_job/jobs_filter.rb b/engine/app/filters/good_job/jobs_filter.rb index c319a4e25..a6192192f 100644 --- a/engine/app/filters/good_job/jobs_filter.rb +++ b/engine/app/filters/good_job/jobs_filter.rb @@ -14,7 +14,7 @@ def states private - def base_query + def default_base_query GoodJob::ActiveJobJob.all end diff --git a/engine/app/views/good_job/cron_entries/index.html.erb b/engine/app/views/good_job/cron_entries/index.html.erb new file mode 100644 index 000000000..22936e251 --- /dev/null +++ b/engine/app/views/good_job/cron_entries/index.html.erb @@ -0,0 +1,51 @@ +<% if @cron_entries.present? %> +
+
+ + + + + + + + + + + + <% @cron_entries.each do |cron_entry| %> + + + + + + + + + + <% end %> + +
KeySchedule + 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(" ") } + %> + DescriptionNext scheduledLast runActions
<%= cron_entry.key %><%= cron_entry.cron %> + <%= 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") %> + <%= cron_entry.description %><%= cron_entry.next_at %> + <% 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 %> + + <%= 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 %> +
+
+
+<% else %> + No cron schedules present. +<% end %> diff --git a/engine/app/views/good_job/cron_entries/show.html.erb b/engine/app/views/good_job/cron_entries/show.html.erb new file mode 100644 index 000000000..ecaf8c79c --- /dev/null +++ b/engine/app/views/good_job/cron_entries/show.html.erb @@ -0,0 +1,4 @@ +

Cron Entry Key: <%= @cron_entry.id %>

+ +<%= render 'good_job/shared/filter', filter: @jobs_filter %> +<%= render 'good_job/jobs/table', jobs: @jobs_filter.records %> diff --git a/engine/app/views/good_job/cron_schedules/index.html.erb b/engine/app/views/good_job/cron_schedules/index.html.erb deleted file mode 100644 index 16622dd29..000000000 --- a/engine/app/views/good_job/cron_schedules/index.html.erb +++ /dev/null @@ -1,72 +0,0 @@ -<% if @cron_entries.present? %> -
-
- - - - - - - - - - - - <% @cron_entries.each do |cron_entry| %> - - - - - - - - - - <% end %> - -
Cron Job NameConfiguration - Set  - <%= tag.button "Toggle", type: "button", class: "btn btn-sm btn-outline-primary", role: "button", - data: { bs_toggle: "collapse", bs_target: ".job-properties" }, - aria: { expanded: false, controls: @cron_entries.map { |cron_entry| dom_id(cron_entry, 'properties') }.join(" ") } - %> - - Args  - <%= tag.button "Toggle", type: "button", class: "btn btn-sm btn-outline-primary", role: "button", - data: { bs_toggle: "collapse", bs_target: ".job-args" }, - aria: { expanded: false, controls: @cron_entries.map { |cron_entry| dom_id(cron_entry, 'args') }.join(" ") } - %> - ClassDescriptionNext scheduled
<%= cron_entry.key %><%= cron_entry.cron %> - <%= - case cron_entry.set - when NilClass - "None" - when Proc - "Lambda/Callable" - when Hash - 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.set), id: dom_id(cron_entry, 'properties'), class: "collapse job-properties") - end - %> - - <%= - case cron_entry.args - when NilClass - "None" - when Proc - "Lambda/Callable" - when Hash - tag.button("Preview", type: "button", class: "btn btn-sm btn-outline-primary", role: "button", - data: { bs_toggle: "collapse", bs_target: "##{dom_id(cron_entry, 'args')}" }, - aria: { expanded: false, controls: dom_id(cron_entry, 'args') }) + - tag.pre(JSON.pretty_generate(cron_entry.args), id: dom_id(cron_entry, 'args'), class: "collapse job-args") - end - %> - <%= cron_entry.job_class %><%= cron_entry.description %><%= cron_entry.next_at %>
-
-
-<% else %> - No cron jobs present. -<% end %> diff --git a/engine/app/views/good_job/shared/_executions_table.erb b/engine/app/views/good_job/executions/_table.erb similarity index 100% rename from engine/app/views/good_job/shared/_executions_table.erb rename to engine/app/views/good_job/executions/_table.erb diff --git a/engine/app/views/good_job/executions/index.html.erb b/engine/app/views/good_job/executions/index.html.erb index 7d928a913..d0c5ea781 100644 --- a/engine/app/views/good_job/executions/index.html.erb +++ b/engine/app/views/good_job/executions/index.html.erb @@ -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 %>