acidic_job 1.0.0.rc1 → 1.0.0.rc2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea7524fb0e637ffdf7df124528a027f41f29891e2185e8776255c1b96ee3b00d
4
- data.tar.gz: f364ede10a8872ffdaa07127cd7db22ed2886ae90605aeeb9d3e35dc3a7b169a
3
+ metadata.gz: 91e85393ede0eb0d4100449b323a12d1d447acc339a2e365926aae4a35ca34cb
4
+ data.tar.gz: 2278997e2ef132f34c26f31d2d17c6d54fcce32a52cb90517e1b678f43f83ede
5
5
  SHA512:
6
- metadata.gz: ffc3d7f6c3638c8a883421f7e2f82c84739c63165d110faf70c95cd77952dff804b6769c7ac637ec170935d6bf227fd04416b7a75f1b585994376f5fe4965feb
7
- data.tar.gz: ca8d0848c203914fd98fd2252689488b789b24c4ada0f082ba5a3a521463e24f66ec69e1240e087766d6091b2e9d0e5748aaeef81e9a69153b7c6489a0a6e29f
6
+ metadata.gz: 308a693c544f5cd2cc36872aaa403762b54fe474a2f2718e3e3fd03be355df92aa3c5cfcbf4b2be7f8f20207aa847c6174fcc09d4a5e9c169277c50b85f22441
7
+ data.tar.gz: 6329afd0ebbd5ce72bbeeb60aeb5359ffec646723b4c01bb110ce2084557de0282b33252d8a81519637c9a11bf5b241fcf1feefac3216c119beed1b22eb9f8cd
data/.codacy.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ exclude_paths:
3
+ - "**/*.md"
4
+ - "LICENSE"
data/Gemfile.lock CHANGED
@@ -1,15 +1,23 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acidic_job (1.0.0.rc1)
4
+ acidic_job (1.0.0.rc2)
5
5
  activejob (>= 7.1)
6
6
  activerecord (>= 7.1)
7
7
  activesupport (>= 7.1)
8
+ json (>= 2.7.0)
8
9
  railties (>= 7.1)
9
10
 
10
11
  GEM
11
12
  remote: https://rubygems.org/
12
13
  specs:
14
+ actionmailer (7.2.1.1)
15
+ actionpack (= 7.2.1.1)
16
+ actionview (= 7.2.1.1)
17
+ activejob (= 7.2.1.1)
18
+ activesupport (= 7.2.1.1)
19
+ mail (>= 2.8.0)
20
+ rails-dom-testing (~> 2.2)
13
21
  actionpack (7.2.1.1)
14
22
  actionview (= 7.2.1.1)
15
23
  activesupport (= 7.2.1.1)
@@ -51,7 +59,7 @@ GEM
51
59
  base64 (0.2.0)
52
60
  bigdecimal (3.1.8)
53
61
  builder (3.3.0)
54
- chaotic_job (0.2.0)
62
+ chaotic_job (0.3.0)
55
63
  combustion (1.3.7)
56
64
  activesupport (>= 3.0.0)
57
65
  railties (>= 3.0.0)
@@ -59,6 +67,7 @@ GEM
59
67
  concurrent-ruby (1.3.4)
60
68
  connection_pool (2.4.0)
61
69
  crass (1.0.6)
70
+ date (3.4.1)
62
71
  docile (1.4.0)
63
72
  drb (2.2.1)
64
73
  erubi (1.13.0)
@@ -70,13 +79,28 @@ GEM
70
79
  irb (1.14.1)
71
80
  rdoc (>= 4.0.0)
72
81
  reline (>= 0.4.2)
73
- json (2.6.3)
82
+ json (2.10.2)
74
83
  logger (1.6.1)
75
84
  loofah (2.22.0)
76
85
  crass (~> 1.0.2)
77
86
  nokogiri (>= 1.12.0)
87
+ mail (2.8.1)
88
+ mini_mime (>= 0.1.1)
89
+ net-imap
90
+ net-pop
91
+ net-smtp
92
+ mini_mime (1.1.5)
78
93
  mini_portile2 (2.8.7)
79
94
  minitest (5.25.1)
95
+ net-imap (0.5.1)
96
+ date
97
+ net-protocol
98
+ net-pop (0.1.2)
99
+ net-protocol
100
+ net-protocol (0.2.2)
101
+ timeout
102
+ net-smtp (0.5.0)
103
+ net-protocol
80
104
  nokogiri (1.16.7)
81
105
  mini_portile2 (~> 2.8.2)
82
106
  racc (~> 1.4)
@@ -162,7 +186,8 @@ PLATFORMS
162
186
 
163
187
  DEPENDENCIES
164
188
  acidic_job!
165
- chaotic_job (>= 0.2.0)
189
+ actionmailer (>= 7.1)
190
+ chaotic_job
166
191
  combustion
167
192
  minitest
168
193
  rake
data/README.md CHANGED
@@ -24,13 +24,13 @@ With AcidicJob, you can write reliable and repeatable multi-step distributed ope
24
24
  Install the gem and add to the application's Gemfile by executing:
25
25
 
26
26
  ```sh
27
- bundle add acidic_job
27
+ bundle add acidic_job --version "1.0.0.rc1"
28
28
  ```
29
29
 
30
30
  If `bundler` is not being used to manage dependencies, install the gem by executing:
31
31
 
32
32
  ```sh
33
- gem install acidic_job
33
+ gem install acidic_job --pre
34
34
  ```
35
35
 
36
36
  After installing the gem, run the installer:
@@ -101,7 +101,8 @@ class RideCreateJob < AcidicJob::Base
101
101
  end
102
102
  ```
103
103
 
104
- The `unique_by` keyword argument is used to define the unique identifier for a particular execution of the workflow. This helps to ensure that the workflow is idempotent, as retries of the job will correctly resume the pre-existing workflow execution. The `unique_by` argument can be anything that `JSON.dump` can handle.
104
+ > [!IMPORTANT]
105
+ > The `unique_by` keyword argument is used to define the unique identifier for a particular execution of the workflow. This helps to ensure that the workflow is idempotent, as retries of the job will correctly resume the pre-existing workflow execution. The `unique_by` argument can **only** be something that `JSON.generate(..., strict: true)` can handle; that is, it must be made up of only the JSON native types: `Hash`, `Array`, `String`, `Integer`, `Float`, `true`, `false` and `nil`.
105
106
 
106
107
  The block passed to `execute_workflow` is where you define the steps of the workflow. Each step is defined by calling the `step` method on the yielded workflow builder object. The `step` method takes the name of a method in the job that will be executed as part of the workflow. The `transactional` keyword argument can be used to ensure that the step is executed within a database transaction.
107
108
 
data/acidic_job.gemspec CHANGED
@@ -27,14 +27,16 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
+ spec.add_dependency "json", ">= 2.7.0" # see: https://github.com/ruby/json/pull/519
30
31
  ">= 7.1".tap do |rails_version|
31
32
  spec.add_dependency "activejob", rails_version
32
33
  spec.add_dependency "activerecord", rails_version
33
34
  spec.add_dependency "activesupport", rails_version
34
35
  spec.add_dependency "railties", rails_version
36
+ spec.add_development_dependency "actionmailer", rails_version
35
37
  end
36
38
 
37
- spec.add_development_dependency "chaotic_job", ">= 0.2.0"
39
+ spec.add_development_dependency "chaotic_job"
38
40
  spec.add_development_dependency "combustion"
39
41
  spec.add_development_dependency "minitest"
40
42
  spec.add_development_dependency "rake"
@@ -6,6 +6,26 @@ module AcidicJob
6
6
  @execution = execution
7
7
  end
8
8
 
9
+ def set(hash)
10
+ AcidicJob.instrument(:set_context, **hash) do
11
+ AcidicJob::Value.upsert_all(
12
+ hash.map do |key, value|
13
+ { execution_id: @execution.id,
14
+ key: key,
15
+ value: value }
16
+ end,
17
+ unique_by: %i[execution_id key]
18
+ )
19
+ end
20
+ end
21
+
22
+ def get(*keys)
23
+ AcidicJob.instrument(:get_context, keys: keys) do
24
+ @execution.values.select(:value).where(key: keys).pluck(:value)
25
+ end
26
+ end
27
+
28
+ # TODO: deprecate these methods
9
29
  def []=(key, value)
10
30
  AcidicJob.instrument(:set_context, key: key, value: value) do
11
31
  AcidicJob::Value.upsert(
@@ -28,9 +28,9 @@ module AcidicJob
28
28
  end
29
29
  end
30
30
 
31
+ # rubocop:disable Lint/MissingSuper
31
32
  class ArgumentMismatchError < Error
32
33
  def initialize(expected, existing)
33
- super
34
34
  @expected = expected
35
35
  @existing = existing
36
36
  end
@@ -46,7 +46,6 @@ module AcidicJob
46
46
 
47
47
  class DefinitionMismatchError < Error
48
48
  def initialize(expected, existing)
49
- super
50
49
  @expected = expected
51
50
  @existing = existing
52
51
  end
@@ -62,7 +61,6 @@ module AcidicJob
62
61
 
63
62
  class UndefinedStepError < Error
64
63
  def initialize(step)
65
- super
66
64
  @step = step
67
65
  end
68
66
 
@@ -73,7 +71,6 @@ module AcidicJob
73
71
 
74
72
  class SucceededStepError < Error
75
73
  def initialize(step)
76
- super
77
74
  @step = step
78
75
  end
79
76
 
@@ -84,7 +81,6 @@ module AcidicJob
84
81
 
85
82
  class UndefinedMethodError < Error
86
83
  def initialize(step)
87
- super
88
84
  @step = step
89
85
  end
90
86
 
@@ -95,7 +91,6 @@ module AcidicJob
95
91
 
96
92
  class InvalidMethodError < Error
97
93
  def initialize(step)
98
- super
99
94
  @step = step
100
95
  end
101
96
 
@@ -103,4 +98,5 @@ module AcidicJob
103
98
  "step method cannot expect arguments: #{@step.inspect}"
104
99
  end
105
100
  end
101
+ # rubocop:enable Lint/MissingSuper
106
102
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AcidicJob
4
- VERSION = "1.0.0.rc1"
4
+ VERSION = "1.0.0.rc2"
5
5
  end
@@ -38,7 +38,7 @@ module AcidicJob
38
38
  else
39
39
  { isolation: :serializable }
40
40
  end
41
- idempotency_key = Digest::SHA256.hexdigest(JSON.dump([self.class.name, unique_by]))
41
+ idempotency_key = Digest::SHA256.hexdigest(JSON.fast_generate([self.class.name, unique_by], strict: true))
42
42
 
43
43
  @execution = ::ActiveRecord::Base.transaction(**transaction_args) do
44
44
  record = Execution.find_by(idempotency_key: idempotency_key)
@@ -129,12 +129,11 @@ module AcidicJob
129
129
 
130
130
  return next_step if @execution.entries.exists?(step: curr_step, action: :succeeded)
131
131
 
132
- step_method = performable_step_for(step_definition)
133
132
  rescued_error = nil
134
133
  begin
135
134
  @execution.record!(step: curr_step, action: :started, timestamp: Time.now)
136
135
  result = AcidicJob.instrument(:perform_step, **step_definition) do
137
- step_method.call
136
+ perform_step_for(step_definition)
138
137
  end
139
138
  case result
140
139
  when REPEAT_STEP
@@ -167,7 +166,7 @@ module AcidicJob
167
166
  end
168
167
  end
169
168
 
170
- def performable_step_for(step_definition)
169
+ def perform_step_for(step_definition)
171
170
  step_name = step_definition.fetch("does")
172
171
  step_method = method(step_name)
173
172
 
@@ -175,9 +174,7 @@ module AcidicJob
175
174
 
176
175
  wrapper = step_definition["transactional"] ? @execution.method(:with_lock) : NO_OP_WRAPPER
177
176
 
178
- proc do
179
- catch(:repeat) { wrapper.call { step_method.call } }
180
- end
177
+ catch(:repeat) { wrapper.call { step_method.call } }
181
178
  rescue NameError
182
179
  raise UndefinedMethodError.new(step_name)
183
180
  end
metadata CHANGED
@@ -1,15 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acidic_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
4
+ version: 1.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - fractaledmind
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-11-17 00:00:00.000000000 Z
10
+ date: 2025-05-14 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: json
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 2.7.0
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 2.7.0
13
26
  - !ruby/object:Gem::Dependency
14
27
  name: activejob
15
28
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +79,34 @@ dependencies:
66
79
  - - ">="
67
80
  - !ruby/object:Gem::Version
68
81
  version: '7.1'
82
+ - !ruby/object:Gem::Dependency
83
+ name: actionmailer
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '7.1'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '7.1'
69
96
  - !ruby/object:Gem::Dependency
70
97
  name: chaotic_job
71
98
  requirement: !ruby/object:Gem::Requirement
72
99
  requirements:
73
100
  - - ">="
74
101
  - !ruby/object:Gem::Version
75
- version: 0.2.0
102
+ version: '0'
76
103
  type: :development
77
104
  prerelease: false
78
105
  version_requirements: !ruby/object:Gem::Requirement
79
106
  requirements:
80
107
  - - ">="
81
108
  - !ruby/object:Gem::Version
82
- version: 0.2.0
109
+ version: '0'
83
110
  - !ruby/object:Gem::Dependency
84
111
  name: combustion
85
112
  requirement: !ruby/object:Gem::Requirement
@@ -199,6 +226,7 @@ executables: []
199
226
  extensions: []
200
227
  extra_rdoc_files: []
201
228
  files:
229
+ - ".codacy.yml"
202
230
  - ".github/FUNDING.yml"
203
231
  - ".github/workflows/main.yml"
204
232
  - ".gitignore"
@@ -249,7 +277,6 @@ metadata:
249
277
  source_code_uri: https://github.com/fractaledmind/acidic_job
250
278
  changelog_uri: https://github.com/fractaledmind/acidic_job/CHANGELOG.md
251
279
  rubygems_mfa_required: 'true'
252
- post_install_message:
253
280
  rdoc_options: []
254
281
  require_paths:
255
282
  - lib
@@ -264,8 +291,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
264
291
  - !ruby/object:Gem::Version
265
292
  version: '0'
266
293
  requirements: []
267
- rubygems_version: 3.5.21
268
- signing_key:
294
+ rubygems_version: 3.6.3
269
295
  specification_version: 4
270
296
  summary: Idempotent operations for Rails apps, built on top of ActiveJob.
271
297
  test_files: []