solid_queue 0.3.1 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 490264bacfa32881edc69e3fa349081bfa1666785db38c7df55824ab6bd538b4
4
- data.tar.gz: b12570f172afad018ac4709c7203276c0ba737ff90654cae02cadc3197be0357
3
+ metadata.gz: 50d118a41d39dff4da741a1e7fb105b47571dd719b883fb53843e7b57f7aff66
4
+ data.tar.gz: a1dc7ff9b71a07f41fab851ea0dd2f16170240e2a465098f98e75a96c33edb4b
5
5
  SHA512:
6
- metadata.gz: b5909c1a726457b029d0de62bd22bf6929d84ebcddf35a56a8a0af10a0be7108ca1eb60ed48294ef77013f03d9e3c0f9b87a34d1e54ec966742abf79f5edd41f
7
- data.tar.gz: daec7288a9652399f5dd75c0c6d8a5d5def60f9772a122a8b6212a675bb2d5e6ccee831156afd59b624204c694276f5011df64a122df7d44b578e848798cb5fe
6
+ metadata.gz: f344e6ba1a395f014fc08437c1322eac9b3f5218874f4b824cacab042d20053ee9a5504601e37864e04ccc956fc1f08fe35979c9d4a7b19dc42cc53ae5502c56
7
+ data.tar.gz: 27e1d8c00e2c68330d52e938bb00ecadaf246678e16b12b0e1269f8a4e8e3328a972b5a007a04d2839baf2edb480e9f0cae3b6099cd6009a75b11e85858ee6e2
@@ -21,6 +21,7 @@ module SolidQueue
21
21
  def retry
22
22
  SolidQueue.instrument(:retry, job_id: job.id) do
23
23
  with_lock do
24
+ job.reset_execution_counters
24
25
  job.prepare_for_execution
25
26
  destroy!
26
27
  end
@@ -6,16 +6,14 @@ module SolidQueue
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  included do
9
- include ConcurrencyControls, Schedulable
9
+ include ConcurrencyControls, Schedulable, Retryable
10
10
 
11
11
  has_one :ready_execution
12
12
  has_one :claimed_execution
13
- has_one :failed_execution
14
13
 
15
14
  after_create :prepare_for_execution
16
15
 
17
16
  scope :finished, -> { where.not(finished_at: nil) }
18
- scope :failed, -> { includes(:failed_execution).where.not(failed_execution: { id: nil }) }
19
17
  end
20
18
 
21
19
  class_methods do
@@ -97,18 +95,10 @@ module SolidQueue
97
95
  end
98
96
  end
99
97
 
100
- def retry
101
- failed_execution&.retry
102
- end
103
-
104
98
  def discard
105
99
  execution&.discard
106
100
  end
107
101
 
108
- def failed_with(exception)
109
- FailedExecution.create_or_find_by!(job_id: id, exception: exception)
110
- end
111
-
112
102
  private
113
103
  def ready
114
104
  ReadyExecution.create_or_find_by!(job_id: id)
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidQueue
4
+ class Job
5
+ module Retryable
6
+ extend ActiveSupport::Concern
7
+
8
+ included do
9
+ has_one :failed_execution
10
+
11
+ scope :failed, -> { includes(:failed_execution).where.not(failed_execution: { id: nil }) }
12
+ end
13
+
14
+ def retry
15
+ failed_execution&.retry
16
+ end
17
+
18
+ def failed_with(exception)
19
+ FailedExecution.create_or_find_by!(job_id: id, exception: exception)
20
+ end
21
+
22
+ def reset_execution_counters
23
+ arguments["executions"] = 0
24
+ arguments["exception_executions"] = {}
25
+ save!
26
+ end
27
+ end
28
+ end
29
+ end
@@ -24,20 +24,21 @@ module SolidQueue
24
24
  return [] if limit <= 0
25
25
 
26
26
  transaction do
27
- job_ids = select_candidates(queue_relation, limit)
28
- lock_candidates(job_ids, process_id)
27
+ candidates = select_candidates(queue_relation, limit)
28
+ lock_candidates(candidates, process_id)
29
29
  end
30
30
  end
31
31
 
32
32
  def select_candidates(queue_relation, limit)
33
- queue_relation.ordered.limit(limit).non_blocking_lock.pluck(:job_id)
33
+ queue_relation.ordered.limit(limit).non_blocking_lock.select(:id, :job_id)
34
34
  end
35
35
 
36
- def lock_candidates(job_ids, process_id)
37
- return [] if job_ids.none?
36
+ def lock_candidates(executions, process_id)
37
+ return [] if executions.none?
38
38
 
39
- SolidQueue::ClaimedExecution.claiming(job_ids, process_id) do |claimed|
40
- where(job_id: claimed.pluck(:job_id)).delete_all
39
+ SolidQueue::ClaimedExecution.claiming(executions.map(&:job_id), process_id) do |claimed|
40
+ ids_to_delete = executions.index_by(&:job_id).values_at(*claimed.map(&:job_id)).map(&:id)
41
+ where(id: ids_to_delete).delete_all
41
42
  end
42
43
  end
43
44
 
@@ -24,9 +24,9 @@ module SolidQueue
24
24
  SolidQueue.on_thread_error = config.solid_queue.on_thread_error
25
25
  end
26
26
 
27
- initializer "solid_queue.logger" do |app|
27
+ initializer "solid_queue.logger" do
28
28
  ActiveSupport.on_load(:solid_queue) do
29
- self.logger ||= app.logger
29
+ self.logger = ::Rails.logger if logger == SolidQueue::DEFAULT_LOGGER
30
30
  end
31
31
 
32
32
  SolidQueue::LogSubscriber.attach_to :solid_queue
@@ -1,3 +1,3 @@
1
1
  module SolidQueue
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.3"
3
3
  end
data/lib/solid_queue.rb CHANGED
@@ -20,7 +20,9 @@ loader.setup
20
20
  module SolidQueue
21
21
  extend self
22
22
 
23
- mattr_accessor :logger, default: ActiveSupport::Logger.new($stdout)
23
+ DEFAULT_LOGGER = ActiveSupport::Logger.new($stdout)
24
+
25
+ mattr_accessor :logger, default: DEFAULT_LOGGER
24
26
  mattr_accessor :app_executor, :on_thread_error, :connects_to
25
27
 
26
28
  mattr_accessor :use_skip_locked, default: true
@@ -56,4 +58,6 @@ module SolidQueue
56
58
  def instrument(channel, **options, &block)
57
59
  ActiveSupport::Notifications.instrument("#{channel}.solid_queue", **options, &block)
58
60
  end
61
+
62
+ ActiveSupport.run_load_hooks(:solid_queue, self)
59
63
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solid_queue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rosa Gutierrez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-20 00:00:00.000000000 Z
11
+ date: 2024-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -56,30 +56,30 @@ dependencies:
56
56
  name: concurrent-ruby
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 1.2.2
61
+ version: 1.3.1
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 1.2.2
68
+ version: 1.3.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fugit
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 1.10.1
75
+ version: 1.11.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 1.10.1
82
+ version: 1.11.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: debug
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -199,6 +199,7 @@ files:
199
199
  - app/models/solid_queue/job/concurrency_controls.rb
200
200
  - app/models/solid_queue/job/executable.rb
201
201
  - app/models/solid_queue/job/recurrable.rb
202
+ - app/models/solid_queue/job/retryable.rb
202
203
  - app/models/solid_queue/job/schedulable.rb
203
204
  - app/models/solid_queue/pause.rb
204
205
  - app/models/solid_queue/process.rb