From b5f7c02e1831722010ac745368ac68cb06a635ba Mon Sep 17 00:00:00 2001 From: "Ben Sheldon [he/him]" Date: Sun, 10 Jul 2022 21:25:00 -0700 Subject: [PATCH] Improve Dashboard display of parameters (CronEntry kwargs; Process configuration; Job and Execution database values) --- app/views/good_job/jobs/_executions.erb | 2 +- app/views/good_job/jobs/_table.erb | 4 ++-- lib/models/good_job/cron_entry.rb | 6 ++++-- lib/models/good_job/execution.rb | 8 ++++++++ lib/models/good_job/job.rb | 8 ++++++++ lib/models/good_job/process.rb | 2 ++ 6 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/views/good_job/jobs/_executions.erb b/app/views/good_job/jobs/_executions.erb index f01f01e1c..e6830d7d6 100644 --- a/app/views/good_job/jobs/_executions.erb +++ b/app/views/good_job/jobs/_executions.erb @@ -38,7 +38,7 @@ <% end %>
- <%= tag.pre JSON.pretty_generate(execution.serialized_params), id: dom_id(execution, "params"), class: "collapse bg-light card card-body p-3 my-3" %> + <%= tag.pre JSON.pretty_generate(execution.display_serialized_params), id: dom_id(execution, "params"), class: "collapse bg-light card card-body p-3 my-3" %>
<% end %> <% end %> diff --git a/app/views/good_job/jobs/_table.erb b/app/views/good_job/jobs/_table.erb index 311c14459..b20fa9876 100644 --- a/app/views/good_job/jobs/_table.erb +++ b/app/views/good_job/jobs/_table.erb @@ -13,7 +13,7 @@ Executions Error - ActiveJob Params  + Parameters  <%= tag.button "Toggle", type: "button", class: "btn btn-sm btn-outline-primary", role: "button", data: { bs_toggle: "collapse", bs_target: ".job-params" }, aria: { expanded: false, controls: jobs.map { |job| "##{dom_id(job, "params")}" }.join(" ") } @@ -71,7 +71,7 @@ data: { bs_toggle: "collapse", bs_target: "##{dom_id(job, 'params')}" }, aria: { expanded: false, controls: dom_id(job, "params") } %> - <%= tag.pre JSON.pretty_generate(job.serialized_params), id: dom_id(job, "params"), class: "collapse job-params" %> + <%= tag.pre JSON.pretty_generate(job.display_serialized_params), id: dom_id(job, "params"), class: "collapse job-params" %>
diff --git a/lib/models/good_job/cron_entry.rb b/lib/models/good_job/cron_entry.rb index e94a23fe8..69ee0e2eb 100644 --- a/lib/models/good_job/cron_entry.rb +++ b/lib/models/good_job/cron_entry.rb @@ -112,9 +112,11 @@ def display_properties class: job_class, cron: schedule, set: display_property(set), - args: display_property(args), description: display_property(description), - } + }.tap do |properties| + properties[:args] = display_property(args) if args.present? + properties[:kwargs] = display_property(kwargs) if kwargs.present? + end end private diff --git a/lib/models/good_job/execution.rb b/lib/models/good_job/execution.rb index 1bb1c8503..b47e08e61 100644 --- a/lib/models/good_job/execution.rb +++ b/lib/models/good_job/execution.rb @@ -297,6 +297,14 @@ def status end end + # Return formatted serialized_params for display in the dashboard + # @return [Hash] + def display_serialized_params + serialized_params.merge({ + _good_job: attributes.except('serialized_params', 'locktype', 'owns_advisory_lock'), + }) + end + def running? performed_at? && !finished_at? end diff --git a/lib/models/good_job/job.rb b/lib/models/good_job/job.rb index 4a6a8ed06..806cfc28d 100644 --- a/lib/models/good_job/job.rb +++ b/lib/models/good_job/job.rb @@ -117,6 +117,14 @@ def recent_error head_execution.error || executions[-2]&.error end + # Return formatted serialized_params for display in the dashboard + # @return [Hash] + def display_serialized_params + serialized_params.merge({ + _good_job: attributes.except('serialized_params', 'locktype', 'owns_advisory_lock'), + }) + end + # Tests whether the job is being executed right now. # @return [Boolean] def running? diff --git a/lib/models/good_job/process.rb b/lib/models/good_job/process.rb index a9aa79bfe..daf30041c 100644 --- a/lib/models/good_job/process.rb +++ b/lib/models/good_job/process.rb @@ -45,6 +45,8 @@ def self.current_state hostname: Socket.gethostname, pid: ::Process.pid, proctitle: $PROGRAM_NAME, + preserve_job_records: GoodJob.preserve_job_records, + retry_on_unhandled_error: GoodJob.retry_on_unhandled_error, schedulers: GoodJob::Scheduler.instances.map(&:name), } end