solid_queue 0.3.2 → 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: 0b3a20c6db61dce133b76763ea92b6a5b47f99b0b42d42a3e7360a616b148242
4
- data.tar.gz: 5cfbd1488c274f304ab92d989703b395ceb5d7b6f277b20d053e84de0f3dd649
3
+ metadata.gz: 50d118a41d39dff4da741a1e7fb105b47571dd719b883fb53843e7b57f7aff66
4
+ data.tar.gz: a1dc7ff9b71a07f41fab851ea0dd2f16170240e2a465098f98e75a96c33edb4b
5
5
  SHA512:
6
- metadata.gz: 07dbf7e8bb7ac1e7082104ee1d22dcd409b6a6a1d6f899b8c39b1690e1128e40e1e3dbc998d78caa634f464d8b9ce873ba6d519bef004e9cf7e11db9e90d098d
7
- data.tar.gz: 5c97353fa00bb68b561cffbb50af26b7229083afc51951a749471d1871932d13a4fb2d89a54bdac8dadbc6704ff09eab17e5ae1bf9d013f66ca8c08a9182c8e8
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
 
@@ -1,3 +1,3 @@
1
1
  module SolidQueue
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  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.2
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-30 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
@@ -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