parallel_workforce 2.0.0 → 3.0.0

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: 9ef8716bb08d920fb76459016cdb615f50d89e5604066ff01ad723d2b4fb03b4
4
- data.tar.gz: 6263caa320d791299cfe76e399f26c23d49414ca8536cef25358fc10dfc5f8a3
3
+ metadata.gz: 2e38b7ae0d29c7bef029f3188bfaa9e425ce7c0927a3785b01dc760f81c089ca
4
+ data.tar.gz: 4f29cb1e4de7497342d822f528597a42b3462feb8f0ebcab9eddbed2528e1224
5
5
  SHA512:
6
- metadata.gz: 9bb0c64bd4fa27720d5db3d174cee1d2954ffba8cbdcc7153c1f644eada79440a8340a49f703f3a32cabb12f6bfbd71f7b9a7a64d7667b9c69a75b54be035b6e
7
- data.tar.gz: 2529e7806726359ecd5ca4c5c994863b57eb029576bd1e94577f2dbe658df0cccdccd3a45909384fd6551c2b0b59fb4fb11f1e5a8f3ebf619226a1a2fe2c9e12
6
+ metadata.gz: d8e78436dadff0af8d50c3b7400f4633374c85abaa790a8148866c4e3b2c2620f4ffa001b6fac0f7ed0257658ad2a836995cc63bb2c48f8a2f6cfb768976baaa
7
+ data.tar.gz: 242fa4f95c27ca8f9a32b97954d7e5d86022dc44815b8d459023df45a4965a23a0c0f199e5d471993943762c5d5e0e6ad27d8f747cdf6ec6c11bbe3ca45a50b8
@@ -42,6 +42,9 @@ RSpec/DescribedClass:
42
42
  # RSpec/VerifiedDoubles:
43
43
  # Enabled: true
44
44
 
45
+ Layout/FirstParameterIndentation:
46
+ Enabled: false
47
+
45
48
  Layout/AlignHash:
46
49
  Enabled: false
47
50
 
@@ -135,15 +138,6 @@ Style/GuardClause:
135
138
  Style/IfUnlessModifier:
136
139
  Enabled: false
137
140
 
138
- Layout/IndentFirstArgument:
139
- Enabled: false
140
-
141
- Naming/RescuedExceptionsVariableName:
142
- Enabled: false
143
-
144
- Layout/IndentFirstArrayElement:
145
- EnforcedStyle: consistent
146
-
147
141
  Layout/MultilineOperationIndentation:
148
142
  Enabled: true
149
143
  EnforcedStyle: indented
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- parallel_workforce (2.0.0)
4
+ parallel_workforce (3.0.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -146,6 +146,7 @@ GEM
146
146
  sprockets (>= 3.0.0)
147
147
  thor (0.20.3)
148
148
  thread_safe (0.3.6)
149
+ timecop (0.9.4)
149
150
  tzinfo (1.2.5)
150
151
  thread_safe (~> 0.1)
151
152
  unicode-display_width (1.4.1)
@@ -164,6 +165,7 @@ DEPENDENCIES
164
165
  rubocop (~> 0.65)
165
166
  rubocop-rspec (~> 1.32)
166
167
  sidekiq (~> 4.0)
168
+ timecop (~> 0.9)
167
169
 
168
170
  BUNDLED WITH
169
171
  1.17.3
@@ -1,11 +1,14 @@
1
1
  module ParallelWorkforce
2
2
  module Job
3
- class ActiveJob < ActiveJob::Base
3
+ class ActiveJob < ::ActiveJob::Base
4
+ include ParallelWorkforce::Job::Util::JobHelper
5
+
4
6
  discard_on Exception if defined?(discard_on)
5
7
 
6
8
  class << self
7
9
  def enqueue_actor(actor_class_name:, result_key:, index:, server_revision:, serialized_actor_args:)
8
- perform_later(
10
+ enqueue_actor_job(
11
+ :perform_later,
9
12
  actor_class_name: actor_class_name,
10
13
  result_key: result_key,
11
14
  index: index,
@@ -16,7 +19,7 @@ module ParallelWorkforce
16
19
  end
17
20
 
18
21
  def perform(args)
19
- ParallelWorkforce::Job::Util::Performer.new(**args.symbolize_keys).perform
22
+ invoke_performer(args)
20
23
  end
21
24
  end
22
25
  end
@@ -3,7 +3,8 @@ module ParallelWorkforce
3
3
  class ActiveJobRails < ParallelWorkforce::Job::ActiveJob
4
4
  class << self
5
5
  def enqueue_actor(actor_class_name:, result_key:, index:, server_revision:, serialized_actor_args:)
6
- perform_later(
6
+ enqueue_actor_job(
7
+ :perform_later,
7
8
  actor_class_name: actor_class_name,
8
9
  result_key: result_key,
9
10
  index: index,
@@ -15,10 +16,7 @@ module ParallelWorkforce
15
16
  end
16
17
 
17
18
  def perform(args)
18
- args.symbolize_keys!
19
- Time.use_zone(args.delete(:time_zone_name)) do
20
- ParallelWorkforce::Job::Util::Performer.new(**args).perform
21
- end
19
+ invoke_performer_with_time_zone_name(args)
22
20
  end
23
21
  end
24
22
  end
@@ -2,12 +2,14 @@ module ParallelWorkforce
2
2
  module Job
3
3
  class Sidekiq
4
4
  include ::Sidekiq::Worker
5
+ include ParallelWorkforce::Job::Util::JobHelper
5
6
 
6
7
  sidekiq_options retry: false
7
8
 
8
9
  class << self
9
10
  def enqueue_actor(actor_class_name:, result_key:, index:, server_revision:, serialized_actor_args:)
10
- perform_async(
11
+ enqueue_actor_job(
12
+ :perform_async,
11
13
  actor_class_name: actor_class_name,
12
14
  result_key: result_key,
13
15
  index: index,
@@ -18,8 +20,7 @@ module ParallelWorkforce
18
20
  end
19
21
 
20
22
  def perform(args)
21
- args = args.each_with_object({}) { |(k, v), result| result[k.to_sym] = v }
22
- ParallelWorkforce::Job::Util::Performer.new(**args).perform
23
+ invoke_performer(args)
23
24
  end
24
25
  end
25
26
  end
@@ -3,7 +3,8 @@ module ParallelWorkforce
3
3
  class SidekiqRails < ParallelWorkforce::Job::Sidekiq
4
4
  class << self
5
5
  def enqueue_actor(actor_class_name:, result_key:, index:, server_revision:, serialized_actor_args:)
6
- perform_async(
6
+ enqueue_actor_job(
7
+ :perform_async,
7
8
  actor_class_name: actor_class_name,
8
9
  result_key: result_key,
9
10
  index: index,
@@ -15,10 +16,7 @@ module ParallelWorkforce
15
16
  end
16
17
 
17
18
  def perform(args)
18
- args.symbolize_keys!
19
- Time.use_zone(args.delete(:time_zone_name)) do
20
- ParallelWorkforce::Job::Util::Performer.new(**args).perform
21
- end
19
+ invoke_performer_with_time_zone_name(args)
22
20
  end
23
21
  end
24
22
  end
@@ -0,0 +1,60 @@
1
+ module ParallelWorkforce
2
+ module Job
3
+ module Util
4
+ module JobHelper
5
+ def self.included(klass)
6
+ klass.extend(ClassMethods)
7
+ end
8
+
9
+ module ClassMethods
10
+ def build_serialized_actor_args_key(result_key, index)
11
+ "#{result_key}:#{index}:serialized-actor-args"
12
+ end
13
+
14
+ def enqueue_actor_job(enqueue_method, **kwargs)
15
+ serialized_actor_args = kwargs.delete(:serialized_actor_args)
16
+
17
+ ::ParallelWorkforce.configuration.redis_connector.with do |redis|
18
+ redis.setex(
19
+ build_serialized_actor_args_key(kwargs[:result_key], kwargs[:index]),
20
+ ::ParallelWorkforce.configuration.job_key_expiration,
21
+ serialized_actor_args,
22
+ )
23
+ end
24
+
25
+ send(
26
+ enqueue_method,
27
+ **kwargs,
28
+ )
29
+ end
30
+ end
31
+
32
+ def invoke_performer(args)
33
+ args.transform_keys!(&:to_sym)
34
+
35
+ serialized_actor_args = ParallelWorkforce.configuration.redis_connector.with do |redis|
36
+ serialized_actor_args_key = self.class.build_serialized_actor_args_key(args[:result_key], args[:index])
37
+
38
+ redis.getset(serialized_actor_args_key, nil).tap do
39
+ redis.del(serialized_actor_args_key)
40
+ end
41
+ end
42
+
43
+ raise "Unable to locate serialized data required for Performer" if serialized_actor_args.nil?
44
+
45
+ args[:serialized_actor_args] = serialized_actor_args
46
+
47
+ ParallelWorkforce::Job::Util::Performer.new(**args).perform
48
+ end
49
+
50
+ def invoke_performer_with_time_zone_name(args)
51
+ args.transform_keys!(&:to_sym)
52
+
53
+ Time.use_zone(args.delete(:time_zone_name)) do
54
+ invoke_performer(args)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -2,6 +2,7 @@ require_relative "version"
2
2
  require_relative "executor"
3
3
  require_relative "configuration"
4
4
  require_relative "job/util/performer"
5
+ require_relative "job/util/job_helper"
5
6
  require_relative "redis_connector/redis_pool"
6
7
  require_relative "revision_builder/files_hash"
7
8
  require_relative "serializer/marshal"
@@ -1,3 +1,3 @@
1
1
  module ParallelWorkforce
2
- VERSION = "2.0.0".freeze
2
+ VERSION = "3.0.0".freeze
3
3
  end
@@ -44,5 +44,6 @@ Gem::Specification.new do |spec|
44
44
  spec.add_development_dependency "rubocop", "~> 0.65"
45
45
  spec.add_development_dependency "rubocop-rspec", "~> 1.32"
46
46
  spec.add_development_dependency "sidekiq", "~> 4.0"
47
+ spec.add_development_dependency "timecop", "~> 0.9"
47
48
  end
48
49
  # rubocop:enable Metrics/BlockLength
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallel_workforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Pearce
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-12 00:00:00.000000000 Z
11
+ date: 2021-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '4.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: timecop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.9'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.9'
139
153
  description: Simplify parallel code execution into workers.
140
154
  email:
141
155
  - michael.p@enjoy.com
@@ -163,6 +177,7 @@ files:
163
177
  - lib/parallel_workforce/job/active_job_rails.rb
164
178
  - lib/parallel_workforce/job/sidekiq.rb
165
179
  - lib/parallel_workforce/job/sidekiq_rails.rb
180
+ - lib/parallel_workforce/job/util/job_helper.rb
166
181
  - lib/parallel_workforce/job/util/performer.rb
167
182
  - lib/parallel_workforce/redis_connector/redis_pool.rb
168
183
  - lib/parallel_workforce/redis_connector/sidekiq_redis_pool.rb
@@ -194,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
209
  - !ruby/object:Gem::Version
195
210
  version: '0'
196
211
  requirements: []
197
- rubygems_version: 3.0.3
212
+ rubygems_version: 3.0.9
198
213
  signing_key:
199
214
  specification_version: 4
200
215
  summary: Simplify parallel code execution into workers