sidekiq_bulk_job 0.1.1 → 0.1.2

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: 1acd50d98090657e0c060fd63d2d1733214b964447a233b7a2a4a83b65e54db2
4
- data.tar.gz: be8c7002b9200fcf374067ff49aa0208866ba50f218beedc91b021c42ecfa2b4
3
+ metadata.gz: e3f6ce66f186f36e576e2611b892ecbb013f888b54f27bbc36f1a463aedc7b1f
4
+ data.tar.gz: 8deff846fe66b2fa565af200678aa20a67ba0ef1550ef920fb5930da0d76bd22
5
5
  SHA512:
6
- metadata.gz: e9b0fee851c8445ef0bc811a16f95716b5c772d3542b83be95c24c60246c0ea91cae491f1b428f8681cfba9bf3464c032779af4cc14664a550ace37fec1d3bff
7
- data.tar.gz: bcf7ceea6a57f54c414c4a1194b5feb5880aaa3fabbe48f72d95016b3bdce059652cb21ed1e511363d56d17519e78bc0075be9d06b0e143d4709fab4f050f811
6
+ metadata.gz: 1199ea0291f826b28e7eb7e3fac6c5c00e98c69d37adc46e110e567ec82977ad3519c15fada8df89b07d5237161f457ab1c71271797897eff37f7677c0e26359
7
+ data.tar.gz: 1cb8a1f0c85caa3c05c994e1412b679251293d333b9d0b30831c13130e68a480035e484d73249e7be28645e01c7f237ea9dfd5348bdb1f97e16f73375faaa144
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sidekiq_bulk_job (0.1.0)
4
+ sidekiq_bulk_job (0.1.2)
5
5
  sidekiq (~> 5.2.7)
6
6
 
7
7
  GEM
@@ -23,7 +23,7 @@ module SidekiqBulkJob
23
23
  end
24
24
 
25
25
  def perform_async(job_class, *args)
26
- options = Utils.symbolize_keys(@opts)
26
+ options = SidekiqBulkJob::Utils.symbolize_keys(@opts)
27
27
  if options[:at].nil? && options[:in].nil?
28
28
  payload = {
29
29
  job_class_name: job_class.to_s,
@@ -45,7 +45,7 @@ module SidekiqBulkJob
45
45
 
46
46
  # Optimization to enqueue something now that is scheduled to go out now or in the past
47
47
  if ts > now.to_f
48
- options = Utils.symbolize_keys(@opts)
48
+ options = SidekiqBulkJob::Utils.symbolize_keys(@opts)
49
49
  payload = {
50
50
  job_class_name: job_class.to_s,
51
51
  at: ts,
@@ -9,11 +9,16 @@ module SidekiqBulkJob
9
9
  sidekiq_options queue: :default, retry: false
10
10
 
11
11
  def perform(job_class_name, args_array)
12
- job = Utils.constantize(job_class_name)
12
+ target_name, method_name = SidekiqBulkJob::Utils.split_class_name_with_method job_class_name
13
+ job = SidekiqBulkJob::Utils.constantize(target_name)
13
14
  args_array.each do |_args|
14
15
  begin
15
16
  args = JSON.parse _args
16
- job.new.send(:perform, *args)
17
+ if SidekiqBulkJob::Utils.class_with_method?(job_class_name)
18
+ job.send(method_name, *args)
19
+ else
20
+ job.new.send(method_name, *args)
21
+ end
17
22
  rescue Exception => e
18
23
  SidekiqBulkJob.logger.error("#{job_class_name} Args: #{args}, Error: #{e.full_message}")
19
24
  SidekiqBulkJob.fail_callback(job_class_name: job_class_name, args: args, exception: e)
@@ -37,8 +37,8 @@ module SidekiqBulkJob
37
37
  end
38
38
 
39
39
  def queue(woker)
40
- if !woker.sidekiq_options.nil? && !woker.sidekiq_options.empty?
41
- sidekiq_options = Utils.symbolize_keys(woker.sidekiq_options)
40
+ if woker.included_modules.include?(Sidekiq::Worker) && !woker.sidekiq_options.nil? && !woker.sidekiq_options.empty?
41
+ sidekiq_options = SidekiqBulkJob::Utils.symbolize_keys(woker.sidekiq_options)
42
42
  if !sidekiq_options[:queue].nil?
43
43
  sidekiq_options[:queue]
44
44
  end
@@ -9,12 +9,17 @@ module SidekiqBulkJob
9
9
  sidekiq_options queue: :default, retry: false
10
10
 
11
11
  def perform(job_class_name, args_redis_key)
12
- job = Utils.constantize(job_class_name)
12
+ target_name, method_name = SidekiqBulkJob::Utils.split_class_name_with_method job_class_name
13
+ job = SidekiqBulkJob::Utils.constantize(target_name)
13
14
  args_array = SidekiqBulkJob.flush args_redis_key
14
15
  args_array.each do |_args|
15
16
  begin
16
17
  args = JSON.parse _args
17
- job.new.send(:perform, *args)
18
+ if SidekiqBulkJob::Utils.class_with_method?(job_class_name)
19
+ job.send(method_name, *args)
20
+ else
21
+ job.new.send(method_name, *args)
22
+ end
18
23
  rescue Exception => e
19
24
  SidekiqBulkJob.logger.error("#{job_class_name} Args: #{args}, Error: #{e.full_message}")
20
25
  SidekiqBulkJob.fail_callback(job_class_name: job_class_name, args: args, exception: e)
@@ -1,72 +1,86 @@
1
- module Utils
1
+ module SidekiqBulkJob
2
+ module Utils
2
3
 
3
- class << self
4
+ class << self
4
5
 
5
- def symbolize_keys(obj)
6
- case obj
7
- when Array
8
- obj.inject([]){|res, val|
9
- res << case val
10
- when Hash, Array
11
- symbolize_keys(val)
12
- else
13
- val
14
- end
15
- res
16
- }
17
- when Hash
18
- obj.inject({}){|res, (key, val)|
19
- nkey = case key
20
- when String
21
- key.to_sym
22
- else
23
- key
24
- end
25
- nval = case val
26
- when Hash, Array
27
- symbolize_keys(val)
28
- else
29
- val
30
- end
31
- res[nkey] = nval
32
- res
33
- }
34
- else
35
- obj
6
+ def symbolize_keys(obj)
7
+ case obj
8
+ when Array
9
+ obj.inject([]){|res, val|
10
+ res << case val
11
+ when Hash, Array
12
+ symbolize_keys(val)
13
+ else
14
+ val
15
+ end
16
+ res
17
+ }
18
+ when Hash
19
+ obj.inject({}){|res, (key, val)|
20
+ nkey = case key
21
+ when String
22
+ key.to_sym
23
+ else
24
+ key
25
+ end
26
+ nval = case val
27
+ when Hash, Array
28
+ symbolize_keys(val)
29
+ else
30
+ val
31
+ end
32
+ res[nkey] = nval
33
+ res
34
+ }
35
+ else
36
+ obj
37
+ end
36
38
  end
37
- end
38
39
 
39
- def constantize(camel_cased_word)
40
- names = camel_cased_word.split("::")
40
+ def constantize(camel_cased_word)
41
+ names = camel_cased_word.split("::")
41
42
 
42
- # Trigger a built-in NameError exception including the ill-formed constant in the message.
43
- Object.const_get(camel_cased_word) if names.empty?
43
+ # Trigger a built-in NameError exception including the ill-formed constant in the message.
44
+ Object.const_get(camel_cased_word) if names.empty?
44
45
 
45
- # Remove the first blank element in case of '::ClassName' notation.
46
- names.shift if names.size > 1 && names.first.empty?
46
+ # Remove the first blank element in case of '::ClassName' notation.
47
+ names.shift if names.size > 1 && names.first.empty?
47
48
 
48
- names.inject(Object) do |constant, name|
49
- if constant == Object
50
- constant.const_get(name)
51
- else
52
- candidate = constant.const_get(name)
53
- next candidate if constant.const_defined?(name, false)
54
- next candidate unless Object.const_defined?(name)
49
+ names.inject(Object) do |constant, name|
50
+ if constant == Object
51
+ constant.const_get(name)
52
+ else
53
+ candidate = constant.const_get(name)
54
+ next candidate if constant.const_defined?(name, false)
55
+ next candidate unless Object.const_defined?(name)
56
+
57
+ # Go down the ancestors to check if it is owned directly. The check
58
+ # stops when we reach Object or the end of ancestors tree.
59
+ constant = constant.ancestors.inject(constant) do |const, ancestor|
60
+ break const if ancestor == Object
61
+ break ancestor if ancestor.const_defined?(name, false)
62
+ const
63
+ end
55
64
 
56
- # Go down the ancestors to check if it is owned directly. The check
57
- # stops when we reach Object or the end of ancestors tree.
58
- constant = constant.ancestors.inject(constant) do |const, ancestor|
59
- break const if ancestor == Object
60
- break ancestor if ancestor.const_defined?(name, false)
61
- const
65
+ # owner is in Object, so raise
66
+ constant.const_get(name, false)
62
67
  end
68
+ end
69
+ end
63
70
 
64
- # owner is in Object, so raise
65
- constant.const_get(name, false)
71
+ def class_with_method?(klass_name)
72
+ klass_name.include?('.')
73
+ end
74
+
75
+ def split_class_name_with_method(klass_name)
76
+ if class_with_method?(klass_name)
77
+ klass_name.split('.')
78
+ else
79
+ [klass_name, :perform]
66
80
  end
67
81
  end
82
+
68
83
  end
69
84
 
70
85
  end
71
-
72
86
  end
@@ -1,3 +1,3 @@
1
1
  module SidekiqBulkJob
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq_bulk_job
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - scalaview
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-09 00:00:00.000000000 Z
11
+ date: 2020-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sidekiq