acidic_job 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/Gemfile.lock +8 -1
- data/bin/console +1 -0
- data/lib/acidic_job.rb +21 -29
- data/lib/acidic_job/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fb1de28508c8a662b772a9b9f8fb4046d8c2a64e242826ec92c1ecc820dbc18b
|
|
4
|
+
data.tar.gz: a0db4307ec7d7c971d9a5e1ff30ccb2243afa9ea35a7f17fe91f8c81d775a52b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0e39981533a09f2f197f8c047d057328be88c5a34666bd8520500a805bee7fb4d86ac74fdebe673cd67fe92c3faff072a3d62eef79e4e14b21ffdfb05b292e2b
|
|
7
|
+
data.tar.gz: b2eb0c3c2fe92b27fc065fc0a450261743b3b6b397c2212e1b46ed4773074342c64c8433930b71f4125a71b9c692f5baa1d29b3ec9d9fc6ac13905c1fe4e2d2f
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
acidic_job (0.1.
|
|
4
|
+
acidic_job (0.1.4)
|
|
5
5
|
activesupport
|
|
6
6
|
|
|
7
7
|
GEM
|
|
@@ -53,6 +53,10 @@ GEM
|
|
|
53
53
|
unicode-display_width (>= 1.4.0, < 3.0)
|
|
54
54
|
rubocop-ast (1.7.0)
|
|
55
55
|
parser (>= 3.0.1.1)
|
|
56
|
+
rubocop-minitest (0.14.0)
|
|
57
|
+
rubocop (>= 0.90, < 2.0)
|
|
58
|
+
rubocop-rake (0.6.0)
|
|
59
|
+
rubocop (~> 1.0)
|
|
56
60
|
ruby-progressbar (1.11.0)
|
|
57
61
|
simplecov (0.21.2)
|
|
58
62
|
docile (~> 1.1)
|
|
@@ -67,6 +71,7 @@ GEM
|
|
|
67
71
|
zeitwerk (2.4.2)
|
|
68
72
|
|
|
69
73
|
PLATFORMS
|
|
74
|
+
ruby
|
|
70
75
|
x86_64-darwin-17
|
|
71
76
|
|
|
72
77
|
DEPENDENCIES
|
|
@@ -77,6 +82,8 @@ DEPENDENCIES
|
|
|
77
82
|
minitest (~> 5.0)
|
|
78
83
|
rake (~> 13.0)
|
|
79
84
|
rubocop (~> 1.7)
|
|
85
|
+
rubocop-minitest
|
|
86
|
+
rubocop-rake
|
|
80
87
|
simplecov
|
|
81
88
|
sqlite3
|
|
82
89
|
|
data/bin/console
CHANGED
data/lib/acidic_job.rb
CHANGED
|
@@ -6,7 +6,7 @@ require_relative "acidic_job/recovery_point"
|
|
|
6
6
|
require_relative "acidic_job/response"
|
|
7
7
|
require "active_support/concern"
|
|
8
8
|
|
|
9
|
-
# rubocop:disable Metrics/ModuleLength, Style/Documentation, Metrics/AbcSize, Metrics/MethodLength
|
|
9
|
+
# rubocop:disable Metrics/ModuleLength, Style/Documentation, Metrics/AbcSize, Metrics/MethodLength
|
|
10
10
|
module AcidicJob
|
|
11
11
|
class IdempotencyKeyRequired < StandardError; end
|
|
12
12
|
|
|
@@ -62,12 +62,11 @@ module AcidicJob
|
|
|
62
62
|
IDEMPOTENCY_KEY_MIN_LENGTH = 20
|
|
63
63
|
|
|
64
64
|
# &block
|
|
65
|
-
def idempotently(
|
|
65
|
+
def idempotently(with:)
|
|
66
66
|
# set accessors for each argument passed in to ensure they are available
|
|
67
67
|
# to the step methods the job will have written
|
|
68
68
|
define_accessors_for_passed_arguments(with)
|
|
69
69
|
|
|
70
|
-
validate_passed_idempotency_key(key)
|
|
71
70
|
validate_passed_arguments(with)
|
|
72
71
|
|
|
73
72
|
# execute the block to gather the info on what phases are defined for this job
|
|
@@ -78,7 +77,7 @@ module AcidicJob
|
|
|
78
77
|
|
|
79
78
|
# find or create an AcidicJobKey record to store all information about this job
|
|
80
79
|
# side-effect: will set the @key instance variable
|
|
81
|
-
ensure_idempotency_key_record(
|
|
80
|
+
ensure_idempotency_key_record(job_id, with[:params], defined_steps.first)
|
|
82
81
|
|
|
83
82
|
# if the key record is already marked as finished, immediately return its result
|
|
84
83
|
return @key.succeeded? if @key.finished?
|
|
@@ -110,17 +109,14 @@ module AcidicJob
|
|
|
110
109
|
|
|
111
110
|
private
|
|
112
111
|
|
|
113
|
-
def atomic_phase(key
|
|
112
|
+
def atomic_phase(key, proc = nil, &block)
|
|
114
113
|
error = false
|
|
115
114
|
phase_callable = (proc || block)
|
|
116
115
|
|
|
117
116
|
begin
|
|
118
|
-
|
|
119
|
-
ActiveRecord::Base.transaction(isolation: :read_uncommitted) do
|
|
117
|
+
key.with_lock do
|
|
120
118
|
phase_result = phase_callable.call
|
|
121
119
|
|
|
122
|
-
# TODO: why is this here?
|
|
123
|
-
key ||= @key
|
|
124
120
|
phase_result.call(key: key)
|
|
125
121
|
end
|
|
126
122
|
rescue StandardError => e
|
|
@@ -129,20 +125,26 @@ module AcidicJob
|
|
|
129
125
|
ensure
|
|
130
126
|
# If we're leaving under an error condition, try to unlock the idempotency
|
|
131
127
|
# key right away so that another request can try again.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
puts "Failed to unlock key #{key.id} because of #{e}."
|
|
139
|
-
end
|
|
128
|
+
begin
|
|
129
|
+
key.update_columns(locked_at: nil, error_object: error) if error.present?
|
|
130
|
+
rescue StandardError => e
|
|
131
|
+
# We're already inside an error condition, so swallow any additional
|
|
132
|
+
# errors from here and just send them to logs.
|
|
133
|
+
puts "Failed to unlock key #{key.id} because of #{e}."
|
|
140
134
|
end
|
|
141
135
|
end
|
|
142
136
|
end
|
|
143
137
|
|
|
144
138
|
def ensure_idempotency_key_record(key_val, params, first_step)
|
|
145
|
-
|
|
139
|
+
# isolation_level = case ActiveRecord::Base.connection.adapter_name.downcase.to_sym
|
|
140
|
+
# when :sqlite
|
|
141
|
+
# :read_uncommitted
|
|
142
|
+
# else # :nocov:
|
|
143
|
+
# :serializable # :nocov:
|
|
144
|
+
# end
|
|
145
|
+
isolation_level = :read_uncommitted
|
|
146
|
+
|
|
147
|
+
ActiveRecord::Base.transaction(isolation: isolation_level) do
|
|
146
148
|
@key = AcidicJobKey.find_by(idempotency_key: key_val)
|
|
147
149
|
|
|
148
150
|
if @key
|
|
@@ -167,9 +169,6 @@ module AcidicJob
|
|
|
167
169
|
job_args: params.as_json
|
|
168
170
|
)
|
|
169
171
|
end
|
|
170
|
-
|
|
171
|
-
# no response and no need to set a recovery point
|
|
172
|
-
NoOp.new
|
|
173
172
|
end
|
|
174
173
|
end
|
|
175
174
|
|
|
@@ -184,13 +183,6 @@ module AcidicJob
|
|
|
184
183
|
true
|
|
185
184
|
end
|
|
186
185
|
|
|
187
|
-
def validate_passed_idempotency_key(key)
|
|
188
|
-
raise IdempotencyKeyRequired if key.nil?
|
|
189
|
-
raise IdempotencyKeyTooShort if key.length < IDEMPOTENCY_KEY_MIN_LENGTH
|
|
190
|
-
|
|
191
|
-
true
|
|
192
|
-
end
|
|
193
|
-
|
|
194
186
|
def validate_passed_arguments(attributes)
|
|
195
187
|
missing_attributes = self.class.required_attributes.select do |required_attribute|
|
|
196
188
|
attributes[required_attribute].nil?
|
|
@@ -220,4 +212,4 @@ module AcidicJob
|
|
|
220
212
|
end
|
|
221
213
|
end
|
|
222
214
|
end
|
|
223
|
-
# rubocop:enable Metrics/ModuleLength, Style/Documentation, Metrics/AbcSize, Metrics/MethodLength
|
|
215
|
+
# rubocop:enable Metrics/ModuleLength, Style/Documentation, Metrics/AbcSize, Metrics/MethodLength
|
data/lib/acidic_job/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: acidic_job
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- fractaledmind
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-07-
|
|
11
|
+
date: 2021-07-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|