good_job 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -1
  3. data/README.md +32 -0
  4. data/engine/app/assets/vendor/bootstrap/bootstrap.bundle.min.js +2 -2
  5. data/engine/app/assets/vendor/bootstrap/bootstrap.min.css +2 -2
  6. data/engine/app/controllers/good_job/active_jobs_controller.rb +3 -2
  7. data/engine/app/controllers/good_job/cron_schedules_controller.rb +10 -0
  8. data/engine/app/controllers/good_job/dashboards_controller.rb +17 -16
  9. data/engine/app/controllers/good_job/executions_controller.rb +10 -0
  10. data/engine/app/views/good_job/active_jobs/show.html.erb +3 -1
  11. data/engine/app/views/good_job/cron_schedules/index.html.erb +28 -0
  12. data/engine/app/views/good_job/dashboards/index.html.erb +5 -5
  13. data/engine/app/views/good_job/shared/_executions_table.erb +56 -0
  14. data/engine/app/views/layouts/good_job/base.html.erb +9 -3
  15. data/engine/config/routes.rb +2 -1
  16. data/lib/good_job/active_job_extensions/concurrency.rb +6 -6
  17. data/lib/good_job/adapter.rb +8 -8
  18. data/lib/good_job/cron_manager.rb +3 -3
  19. data/lib/good_job/{current_execution.rb → current_thread.rb} +8 -8
  20. data/lib/good_job/execution.rb +308 -0
  21. data/lib/good_job/job.rb +6 -294
  22. data/lib/good_job/job_performer.rb +2 -2
  23. data/lib/good_job/log_subscriber.rb +4 -4
  24. data/lib/good_job/notifier.rb +3 -3
  25. data/lib/good_job/railtie.rb +2 -2
  26. data/lib/good_job/scheduler.rb +2 -2
  27. data/lib/good_job/version.rb +1 -1
  28. data/lib/good_job.rb +2 -2
  29. metadata +8 -5
  30. data/engine/app/controllers/good_job/jobs_controller.rb +0 -10
  31. data/engine/app/views/good_job/shared/_jobs_table.erb +0 -48
@@ -14,8 +14,8 @@ module GoodJob
14
14
  def initialize(queue_string)
15
15
  @queue_string = queue_string
16
16
 
17
- @job_query = Concurrent::Delay.new { GoodJob::Job.queue_string(queue_string) }
18
- @parsed_queues = Concurrent::Delay.new { GoodJob::Job.queue_parser(queue_string) }
17
+ @job_query = Concurrent::Delay.new { GoodJob::Execution.queue_string(queue_string) }
18
+ @parsed_queues = Concurrent::Delay.new { GoodJob::Execution.queue_parser(queue_string) }
19
19
  end
20
20
 
21
21
  # A meaningful name to identify the performer in logs and for debugging.
@@ -19,10 +19,10 @@ module GoodJob
19
19
  # @return [void]
20
20
  def create(event)
21
21
  # FIXME: This method does not match any good_job notifications.
22
- good_job = event.payload[:good_job]
22
+ execution = event.payload[:execution]
23
23
 
24
24
  debug do
25
- "GoodJob created job resource with id #{good_job.id}"
25
+ "GoodJob created job resource with id #{execution.id}"
26
26
  end
27
27
  end
28
28
 
@@ -96,12 +96,12 @@ module GoodJob
96
96
 
97
97
  # @!macro notification_responder
98
98
  def perform_job(event)
99
- good_job = event.payload[:good_job]
99
+ execution = event.payload[:execution]
100
100
  process_id = event.payload[:process_id]
101
101
  thread_name = event.payload[:thread_name]
102
102
 
103
103
  info(tags: [process_id, thread_name]) do
104
- "Executed GoodJob #{good_job.id}"
104
+ "Executed GoodJob #{execution.id}"
105
105
  end
106
106
  end
107
107
 
@@ -39,7 +39,7 @@ module GoodJob # :nodoc:
39
39
  # Send a message via Postgres NOTIFY
40
40
  # @param message [#to_json]
41
41
  def self.notify(message)
42
- connection = Job.connection
42
+ connection = Execution.connection
43
43
  connection.exec_query <<~SQL.squish
44
44
  NOTIFY #{CHANNEL}, #{connection.quote(message.to_json)}
45
45
  SQL
@@ -169,8 +169,8 @@ module GoodJob # :nodoc:
169
169
  end
170
170
 
171
171
  def with_listen_connection
172
- ar_conn = Job.connection_pool.checkout.tap do |conn|
173
- Job.connection_pool.remove(conn)
172
+ ar_conn = Execution.connection_pool.checkout.tap do |conn|
173
+ Execution.connection_pool.remove(conn)
174
174
  end
175
175
  pg_conn = ar_conn.raw_connection
176
176
  raise AdapterCannotListenError unless pg_conn.respond_to? :wait_for_notify
@@ -14,11 +14,11 @@ module GoodJob
14
14
 
15
15
  initializer "good_job.active_job_notifications" do
16
16
  ActiveSupport::Notifications.subscribe "enqueue_retry.active_job" do |event|
17
- GoodJob::CurrentExecution.error_on_retry = event.payload[:error]
17
+ GoodJob::CurrentThread.error_on_retry = event.payload[:error]
18
18
  end
19
19
 
20
20
  ActiveSupport::Notifications.subscribe "discard.active_job" do |event|
21
- GoodJob::CurrentExecution.error_on_discard = event.payload[:error]
21
+ GoodJob::CurrentThread.error_on_discard = event.payload[:error]
22
22
  end
23
23
  end
24
24
 
@@ -244,8 +244,8 @@ module GoodJob # :nodoc:
244
244
  def instrument(name, payload = {}, &block)
245
245
  payload = payload.reverse_merge({
246
246
  scheduler: self,
247
- process_id: GoodJob::CurrentExecution.process_id,
248
- thread_name: GoodJob::CurrentExecution.thread_name,
247
+ process_id: GoodJob::CurrentThread.process_id,
248
+ thread_name: GoodJob::CurrentThread.thread_name,
249
249
  })
250
250
 
251
251
  ActiveSupport::Notifications.instrument("#{name}.good_job", payload, &block)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module GoodJob
3
3
  # GoodJob gem version.
4
- VERSION = '2.1.0'
4
+ VERSION = '2.2.0'
5
5
  end
data/lib/good_job.rb CHANGED
@@ -20,7 +20,7 @@ require "good_job/railtie"
20
20
  module GoodJob
21
21
  # @!attribute [rw] active_record_parent_class
22
22
  # @!scope class
23
- # The ActiveRecord parent class inherited by +GoodJob::Job+ (default: +ActiveRecord::Base+).
23
+ # The ActiveRecord parent class inherited by +GoodJob::Execution+ (default: +ActiveRecord::Base+).
24
24
  # Use this when using multiple databases or other custom ActiveRecord configuration.
25
25
  # @return [ActiveRecord::Base]
26
26
  # @example Change the base class:
@@ -129,7 +129,7 @@ module GoodJob
129
129
  timestamp = Time.current - older_than
130
130
 
131
131
  ActiveSupport::Notifications.instrument("cleanup_preserved_jobs.good_job", { older_than: older_than, timestamp: timestamp }) do |payload|
132
- deleted_records_count = GoodJob::Job.finished(timestamp).delete_all
132
+ deleted_records_count = GoodJob::Execution.finished(timestamp).delete_all
133
133
 
134
134
  payload[:deleted_records_count] = deleted_records_count
135
135
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: good_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Sheldon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-09 00:00:00.000000000 Z
11
+ date: 2021-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activejob
@@ -354,13 +354,15 @@ files:
354
354
  - engine/app/controllers/good_job/active_jobs_controller.rb
355
355
  - engine/app/controllers/good_job/assets_controller.rb
356
356
  - engine/app/controllers/good_job/base_controller.rb
357
+ - engine/app/controllers/good_job/cron_schedules_controller.rb
357
358
  - engine/app/controllers/good_job/dashboards_controller.rb
358
- - engine/app/controllers/good_job/jobs_controller.rb
359
+ - engine/app/controllers/good_job/executions_controller.rb
359
360
  - engine/app/helpers/good_job/application_helper.rb
360
361
  - engine/app/views/good_job/active_jobs/show.html.erb
362
+ - engine/app/views/good_job/cron_schedules/index.html.erb
361
363
  - engine/app/views/good_job/dashboards/index.html.erb
362
364
  - engine/app/views/good_job/shared/_chart.erb
363
- - engine/app/views/good_job/shared/_jobs_table.erb
365
+ - engine/app/views/good_job/shared/_executions_table.erb
364
366
  - engine/app/views/good_job/shared/icons/_check.html.erb
365
367
  - engine/app/views/good_job/shared/icons/_exclamation.html.erb
366
368
  - engine/app/views/good_job/shared/icons/_trash.html.erb
@@ -380,8 +382,9 @@ files:
380
382
  - lib/good_job/cli.rb
381
383
  - lib/good_job/configuration.rb
382
384
  - lib/good_job/cron_manager.rb
383
- - lib/good_job/current_execution.rb
385
+ - lib/good_job/current_thread.rb
384
386
  - lib/good_job/daemon.rb
387
+ - lib/good_job/execution.rb
385
388
  - lib/good_job/execution_result.rb
386
389
  - lib/good_job/job.rb
387
390
  - lib/good_job/job_performer.rb
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
- module GoodJob
3
- class JobsController < GoodJob::BaseController
4
- def destroy
5
- deleted_count = GoodJob::Job.where(id: params[:id]).delete_all
6
- message = deleted_count.positive? ? { notice: "Job deleted" } : { alert: "Job not deleted" }
7
- redirect_to root_path, **message
8
- end
9
- end
10
- end
@@ -1,48 +0,0 @@
1
- <div class="card my-3">
2
- <div class="table-responsive">
3
- <table class="table card-table table-bordered table-hover table-sm mb-0">
4
- <thead>
5
- <tr>
6
- <th>GoodJob ID</th>
7
- <th>ActiveJob ID</th>
8
- <th>Job Class</th>
9
- <th>Queue</th>
10
- <th>Scheduled At</th>
11
- <th>Error</th>
12
- <th>
13
- ActiveJob Params&nbsp;
14
- <%= tag.button "Toggle", type: "button", class: "btn btn-sm btn-outline-primary", role: "button",
15
- data: { bs_toggle: "collapse", bs_target: ".job-params" },
16
- aria: { expanded: false, controls: jobs.map { |job| "##{dom_id(job, "params")}" }.join(" ") }
17
- %>
18
- </th>
19
- <th>Actions</th>
20
- </tr>
21
- </thead>
22
- <tbody>
23
- <% jobs.each do |job| %>
24
- <tr id="<%= dom_id(job) %>">
25
- <td><%= link_to job.id, active_job_path(job.serialized_params['job_id'], anchor: dom_id(job)) %></td>
26
- <td><%= link_to job.serialized_params['job_id'], active_job_path(job.serialized_params['job_id']) %></td>
27
- <td><%= job.serialized_params['job_class'] %></td>
28
- <td><%= job.queue_name %></td>
29
- <td><%= job.scheduled_at || job.created_at %></td>
30
- <td class="text-break"><%= truncate(job.error, length: 1_000) %></td>
31
- <td>
32
- <%= tag.button "Preview", type: "button", class: "btn btn-sm btn-outline-primary", role: "button",
33
- data: { bs_toggle: "collapse", bs_target: "##{dom_id(job, 'params')}" },
34
- aria: { expanded: false, controls: dom_id(job, "params") }
35
- %>
36
- <%= tag.pre JSON.pretty_generate(job.serialized_params), id: dom_id(job, "params"), class: "collapse job-params" %>
37
- </td>
38
- <td>
39
- <%= button_to job_path(job.id), method: :delete, class: "btn btn-sm btn-outline-danger", title: "Delete job" do %>
40
- <%= render "good_job/shared/icons/trash" %>
41
- <% end %>
42
- </td>
43
- </tr>
44
- <% end %>
45
- </tbody>
46
- </table>
47
- </div>
48
- </div>