acidic_job 1.0.0.pre16 → 1.0.0.pre19

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: 53f3b1dca6c15b94a5fef3e2e2bd6c23d4f60a6635fa729426bcd98e08bfcf22
4
- data.tar.gz: 64fe54f8707c255211dba80c678012f4068ccc0fb279a50043afff4812649467
3
+ metadata.gz: cb1a8e3e2658bf86b44012171e33458c6e25803e41c255401575bc772cf033db
4
+ data.tar.gz: a2672fb1755af7ada91b7e8b156cffe951f22d530cbf7d94aee794622f9ad5c8
5
5
  SHA512:
6
- metadata.gz: a657457d4714245dda16796e59e35e91246842e1c7dd92c174ac0469674e0a1145f0c20b55cbae4b02e82f391f8e5e8527ab267d88a82d6868578177ce19db9a
7
- data.tar.gz: 785185e925ae66815668fdecbb8ab66bdf71553ecc52eb0002f3ecbd327b2680bc3777db3caf26e00c664dcd83d138e2142b43eb488aaf26c739c9a3099ddb52
6
+ metadata.gz: d6fc3314e1eb512ef9eab52cada5b7705891563715f1d549912b45b13b85bd0bf778a8950a5657037ddf75e7e81819cf8c85a240c191cb71d615e98ca22c7c3a
7
+ data.tar.gz: 011f57cb97e93bd6e09c2c07d164d06679c8311b8e76a1b1cf9438376e65da5d4d76851cd7e1b6eb4d2f1ffba7064ff722c8cec75db08e78a1e96b7353672d13
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- acidic_job (1.0.0.pre16)
4
+ acidic_job (1.0.0.pre19)
5
5
  activerecord
6
6
  activesupport
7
7
  database_cleaner
@@ -9,67 +9,67 @@ PATH
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- actioncable (7.0.2.3)
13
- actionpack (= 7.0.2.3)
14
- activesupport (= 7.0.2.3)
12
+ actioncable (7.0.3)
13
+ actionpack (= 7.0.3)
14
+ activesupport (= 7.0.3)
15
15
  nio4r (~> 2.0)
16
16
  websocket-driver (>= 0.6.1)
17
- actionmailbox (7.0.2.3)
18
- actionpack (= 7.0.2.3)
19
- activejob (= 7.0.2.3)
20
- activerecord (= 7.0.2.3)
21
- activestorage (= 7.0.2.3)
22
- activesupport (= 7.0.2.3)
17
+ actionmailbox (7.0.3)
18
+ actionpack (= 7.0.3)
19
+ activejob (= 7.0.3)
20
+ activerecord (= 7.0.3)
21
+ activestorage (= 7.0.3)
22
+ activesupport (= 7.0.3)
23
23
  mail (>= 2.7.1)
24
24
  net-imap
25
25
  net-pop
26
26
  net-smtp
27
- actionmailer (7.0.2.3)
28
- actionpack (= 7.0.2.3)
29
- actionview (= 7.0.2.3)
30
- activejob (= 7.0.2.3)
31
- activesupport (= 7.0.2.3)
27
+ actionmailer (7.0.3)
28
+ actionpack (= 7.0.3)
29
+ actionview (= 7.0.3)
30
+ activejob (= 7.0.3)
31
+ activesupport (= 7.0.3)
32
32
  mail (~> 2.5, >= 2.5.4)
33
33
  net-imap
34
34
  net-pop
35
35
  net-smtp
36
36
  rails-dom-testing (~> 2.0)
37
- actionpack (7.0.2.3)
38
- actionview (= 7.0.2.3)
39
- activesupport (= 7.0.2.3)
37
+ actionpack (7.0.3)
38
+ actionview (= 7.0.3)
39
+ activesupport (= 7.0.3)
40
40
  rack (~> 2.0, >= 2.2.0)
41
41
  rack-test (>= 0.6.3)
42
42
  rails-dom-testing (~> 2.0)
43
43
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
44
- actiontext (7.0.2.3)
45
- actionpack (= 7.0.2.3)
46
- activerecord (= 7.0.2.3)
47
- activestorage (= 7.0.2.3)
48
- activesupport (= 7.0.2.3)
44
+ actiontext (7.0.3)
45
+ actionpack (= 7.0.3)
46
+ activerecord (= 7.0.3)
47
+ activestorage (= 7.0.3)
48
+ activesupport (= 7.0.3)
49
49
  globalid (>= 0.6.0)
50
50
  nokogiri (>= 1.8.5)
51
- actionview (7.0.2.3)
52
- activesupport (= 7.0.2.3)
51
+ actionview (7.0.3)
52
+ activesupport (= 7.0.3)
53
53
  builder (~> 3.1)
54
54
  erubi (~> 1.4)
55
55
  rails-dom-testing (~> 2.0)
56
56
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
57
- activejob (7.0.2.3)
58
- activesupport (= 7.0.2.3)
57
+ activejob (7.0.3)
58
+ activesupport (= 7.0.3)
59
59
  globalid (>= 0.3.6)
60
- activemodel (7.0.2.3)
61
- activesupport (= 7.0.2.3)
62
- activerecord (7.0.2.3)
63
- activemodel (= 7.0.2.3)
64
- activesupport (= 7.0.2.3)
65
- activestorage (7.0.2.3)
66
- actionpack (= 7.0.2.3)
67
- activejob (= 7.0.2.3)
68
- activerecord (= 7.0.2.3)
69
- activesupport (= 7.0.2.3)
60
+ activemodel (7.0.3)
61
+ activesupport (= 7.0.3)
62
+ activerecord (7.0.3)
63
+ activemodel (= 7.0.3)
64
+ activesupport (= 7.0.3)
65
+ activestorage (7.0.3)
66
+ actionpack (= 7.0.3)
67
+ activejob (= 7.0.3)
68
+ activerecord (= 7.0.3)
69
+ activesupport (= 7.0.3)
70
70
  marcel (~> 1.0)
71
71
  mini_mime (>= 1.1.0)
72
- activesupport (7.0.2.3)
72
+ activesupport (7.0.3)
73
73
  concurrent-ruby (~> 1.0, >= 1.0.2)
74
74
  i18n (>= 1.6, < 2)
75
75
  minitest (>= 5.1)
@@ -82,7 +82,7 @@ GEM
82
82
  activesupport (>= 3.0.0)
83
83
  railties (>= 3.0.0)
84
84
  thor (>= 0.14.6)
85
- concurrent-ruby (1.1.9)
85
+ concurrent-ruby (1.1.10)
86
86
  connection_pool (2.2.5)
87
87
  crass (1.0.6)
88
88
  database_cleaner (2.0.1)
@@ -112,11 +112,10 @@ GEM
112
112
  http-form_data (2.3.0)
113
113
  i18n (1.10.0)
114
114
  concurrent-ruby (~> 1.0)
115
- io-wait (0.2.1)
116
115
  llhttp-ffi (0.4.0)
117
116
  ffi-compiler (~> 1.0)
118
117
  rake (~> 13.0)
119
- loofah (2.15.0)
118
+ loofah (2.18.0)
120
119
  crass (~> 1.0.2)
121
120
  nokogiri (>= 1.5.9)
122
121
  mail (2.7.1)
@@ -134,52 +133,51 @@ GEM
134
133
  digest
135
134
  net-protocol
136
135
  timeout
137
- net-protocol (0.1.2)
138
- io-wait
136
+ net-protocol (0.1.3)
139
137
  timeout
140
138
  net-smtp (0.3.1)
141
139
  digest
142
140
  net-protocol
143
141
  timeout
144
142
  nio4r (2.5.8)
145
- nokogiri (1.13.3)
143
+ nokogiri (1.13.6)
146
144
  mini_portile2 (~> 2.8.0)
147
145
  racc (~> 1.4)
148
- nokogiri (1.13.3-x86_64-darwin)
146
+ nokogiri (1.13.6-x86_64-darwin)
149
147
  racc (~> 1.4)
150
148
  noticed (1.5.9)
151
149
  http (>= 4.0.0)
152
150
  rails (>= 5.2.0)
153
- parallel (1.21.0)
154
- parser (3.1.1.0)
151
+ parallel (1.22.1)
152
+ parser (3.1.2.0)
155
153
  ast (~> 2.4.1)
156
- public_suffix (4.0.6)
154
+ public_suffix (4.0.7)
157
155
  racc (1.6.0)
158
156
  rack (2.2.3)
159
157
  rack-test (1.1.0)
160
158
  rack (>= 1.0, < 3)
161
- rails (7.0.2.3)
162
- actioncable (= 7.0.2.3)
163
- actionmailbox (= 7.0.2.3)
164
- actionmailer (= 7.0.2.3)
165
- actionpack (= 7.0.2.3)
166
- actiontext (= 7.0.2.3)
167
- actionview (= 7.0.2.3)
168
- activejob (= 7.0.2.3)
169
- activemodel (= 7.0.2.3)
170
- activerecord (= 7.0.2.3)
171
- activestorage (= 7.0.2.3)
172
- activesupport (= 7.0.2.3)
159
+ rails (7.0.3)
160
+ actioncable (= 7.0.3)
161
+ actionmailbox (= 7.0.3)
162
+ actionmailer (= 7.0.3)
163
+ actionpack (= 7.0.3)
164
+ actiontext (= 7.0.3)
165
+ actionview (= 7.0.3)
166
+ activejob (= 7.0.3)
167
+ activemodel (= 7.0.3)
168
+ activerecord (= 7.0.3)
169
+ activestorage (= 7.0.3)
170
+ activesupport (= 7.0.3)
173
171
  bundler (>= 1.15.0)
174
- railties (= 7.0.2.3)
172
+ railties (= 7.0.3)
175
173
  rails-dom-testing (2.0.3)
176
174
  activesupport (>= 4.2.0)
177
175
  nokogiri (>= 1.6)
178
176
  rails-html-sanitizer (1.4.2)
179
177
  loofah (~> 2.3)
180
- railties (7.0.2.3)
181
- actionpack (= 7.0.2.3)
182
- activesupport (= 7.0.2.3)
178
+ railties (7.0.3)
179
+ actionpack (= 7.0.3)
180
+ activesupport (= 7.0.3)
183
181
  method_source
184
182
  rake (>= 12.2)
185
183
  thor (~> 1.0)
@@ -187,25 +185,25 @@ GEM
187
185
  rainbow (3.1.1)
188
186
  rake (13.0.6)
189
187
  redis (4.6.0)
190
- regexp_parser (2.2.1)
188
+ regexp_parser (2.4.0)
191
189
  rexml (3.2.5)
192
- rubocop (1.26.0)
190
+ rubocop (1.29.1)
193
191
  parallel (~> 1.10)
194
192
  parser (>= 3.1.0.0)
195
193
  rainbow (>= 2.2.2, < 4.0)
196
194
  regexp_parser (>= 1.8, < 3.0)
197
- rexml
198
- rubocop-ast (>= 1.16.0, < 2.0)
195
+ rexml (>= 3.2.5, < 4.0)
196
+ rubocop-ast (>= 1.17.0, < 2.0)
199
197
  ruby-progressbar (~> 1.7)
200
198
  unicode-display_width (>= 1.4.0, < 3.0)
201
- rubocop-ast (1.16.0)
199
+ rubocop-ast (1.18.0)
202
200
  parser (>= 3.1.1.0)
203
- rubocop-minitest (0.18.0)
201
+ rubocop-minitest (0.19.1)
204
202
  rubocop (>= 0.90, < 2.0)
205
203
  rubocop-rake (0.6.0)
206
204
  rubocop (~> 1.0)
207
205
  ruby-progressbar (1.11.0)
208
- sidekiq (6.4.1)
206
+ sidekiq (6.4.2)
209
207
  connection_pool (>= 2.2.2)
210
208
  rack (~> 2.0)
211
209
  redis (>= 4.2.0)
@@ -216,7 +214,7 @@ GEM
216
214
  simplecov-html (0.12.3)
217
215
  simplecov_json_formatter (0.1.4)
218
216
  sqlite3 (1.4.2)
219
- strscan (3.0.1)
217
+ strscan (3.0.3)
220
218
  thor (1.2.1)
221
219
  timeout (0.2.0)
222
220
  tzinfo (2.0.4)
@@ -17,8 +17,11 @@ module AcidicJob
17
17
  "#{self.class.name}#step_done",
18
18
  # NOTE: options are marshalled through JSON so use only basic types.
19
19
  { "run_id" => run.id,
20
- "step_result_yaml" => step_result.to_yaml.strip }
20
+ "step_result_yaml" => step_result.to_yaml.strip,
21
+ "parent_worker" => self.class.name,
22
+ "job_names" => jobs.map(&:to_s) }
21
23
  )
24
+
22
25
  # NOTE: The jobs method is atomic.
23
26
  # All jobs created in the block are actually pushed atomically at the end of the block.
24
27
  # If an error is raised, none of the jobs will go to Redis.
@@ -26,7 +29,8 @@ module AcidicJob
26
29
  jobs.each do |worker_name|
27
30
  # TODO: handle Symbols as well
28
31
  worker = worker_name.is_a?(String) ? worker_name.constantize : worker_name
29
- if worker.instance_method(:perform).arity.zero?
32
+
33
+ if worker.instance_method(:perform).arity.presence_in [0, -1]
30
34
  worker.perform_async
31
35
  elsif worker.instance_method(:perform).arity == 1
32
36
  worker.perform_async(run.id)
@@ -25,12 +25,16 @@ module AcidicJob
25
25
  # and `AcidicJob::DeliverAcidicly#deliver_acidicly`
26
26
  def serialize_with_arguments(args = [], _kwargs = nil)
27
27
  # THIS IS A HACK THAT ESSENTIALLY COPIES THE CODE FROM THE SIDEKIQ CODEBASE TO MIMIC THE BEHAVIOR
28
+ # updated to handle Sidekiq v6.4.2 at latest
28
29
  args = Array[args]
29
30
  normalized_args = ::Sidekiq.load_json(::Sidekiq.dump_json(args))
30
31
  item = { "class" => self, "args" => normalized_args }
31
32
  dummy_sidekiq_client = ::Sidekiq::Client.new
32
33
  normed = dummy_sidekiq_client.send :normalize_item, item
33
- dummy_sidekiq_client.send :process_single, item["class"], normed
34
+ redis_pool = dummy_sidekiq_client.instance_variable_get(:@redis_pool)
35
+ dummy_sidekiq_client.middleware.invoke(normed["class"], normed, normed["queue"], redis_pool) do
36
+ normed
37
+ end
34
38
  end
35
39
  end
36
40
 
@@ -52,6 +52,12 @@ module AcidicJob
52
52
  # {"does" => :enqueue_step, "then" => :next_step, "awaits" => [WorkerWithEnqueueStep::FirstWorker]}
53
53
  current_step = step["does"]
54
54
  next_step = step["then"]
55
+ # to support iteration within steps
56
+ iterable_key = step["for_each"]
57
+ iterated_key = "processed_#{current_step}_#{iterable_key}"
58
+ iterables = @run.attr_accessors.fetch(iterable_key, []) || []
59
+ iterateds = @run.attr_accessors.fetch(iterated_key, []) || []
60
+ next_item = iterables.reject { |item| iterateds.include? item }.first
55
61
 
56
62
  # jobs can have no-op steps, especially so that they can use only the async/await mechanism for that step
57
63
  callable = if @job.respond_to?(current_step, _include_private = true)
@@ -62,7 +68,11 @@ module AcidicJob
62
68
 
63
69
  # return a callable Proc with a consistent interface for the execution phase
64
70
  proc do |run|
65
- result = if callable.arity.zero?
71
+ result = if iterable_key.present? && next_item.present?
72
+ callable.call(next_item)
73
+ elsif iterable_key.present? && next_item.nil?
74
+ true
75
+ elsif callable.arity.zero?
66
76
  callable.call
67
77
  elsif callable.arity == 1
68
78
  callable.call(run)
@@ -72,6 +82,11 @@ module AcidicJob
72
82
 
73
83
  if result.is_a?(FinishedPoint)
74
84
  result
85
+ elsif next_item.present?
86
+ iterateds << next_item
87
+ @run.attr_accessors[iterated_key] = iterateds
88
+ @run.save!(validate: false)
89
+ RecoveryPoint.new(current_step)
75
90
  elsif next_step.to_s == Run::FINISHED_RECOVERY_POINT
76
91
  FinishedPoint.new
77
92
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AcidicJob
4
- VERSION = "1.0.0.pre16"
4
+ VERSION = "1.0.0.pre19"
5
5
  end
data/lib/acidic_job.rb CHANGED
@@ -47,7 +47,9 @@ module AcidicJob
47
47
  raise UnknownJobAdapter
48
48
  end
49
49
 
50
+ # TODO: write test for a staged job that uses awaits
50
51
  klass.set_callback :perform, :after, :delete_staged_job_record, if: :was_staged_job?
52
+ klass.define_callbacks :finish
51
53
 
52
54
  klass.instance_variable_set(:@acidic_identifier, :job_id)
53
55
  klass.define_singleton_method(:acidic_by_job_id) { @acidic_identifier = :job_id }
@@ -128,10 +130,10 @@ module AcidicJob
128
130
 
129
131
  def process_run(run)
130
132
  # if the run record is already marked as finished, immediately return its result
131
- return run.succeeded? if run.finished?
133
+ return finish_run(run) if run.finished?
132
134
 
133
135
  # otherwise, we will enter a loop to process each step of the workflow
134
- run.workflow.size.times do
136
+ loop do
135
137
  recovery_point = run.recovery_point.to_s
136
138
  current_step = run.workflow[recovery_point]
137
139
 
@@ -167,15 +169,22 @@ module AcidicJob
167
169
  end
168
170
 
169
171
  # the loop will break once the job is finished, so simply report the status
170
- run.succeeded?
172
+ finish_run(run)
171
173
  end
172
174
 
173
- def step(method_name, awaits: [])
175
+ def finish_run(run)
176
+ run_callbacks :finish do
177
+ run.succeeded?
178
+ end
179
+ end
180
+
181
+ def step(method_name, awaits: [], for_each: nil)
174
182
  @__acidic_job_steps ||= []
175
183
 
176
184
  @__acidic_job_steps << {
177
185
  "does" => method_name.to_s,
178
- "awaits" => awaits
186
+ "awaits" => awaits,
187
+ "for_each" => for_each
179
188
  }
180
189
 
181
190
  @__acidic_job_steps
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: 1.0.0.pre16
4
+ version: 1.0.0.pre19
5
5
  platform: ruby
6
6
  authors:
7
7
  - fractaledmind
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-11 00:00:00.000000000 Z
11
+ date: 2022-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord