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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/sidekiq_bulk_job.rb +2 -2
- data/lib/sidekiq_bulk_job/bulk_job.rb +7 -2
- data/lib/sidekiq_bulk_job/job_retry.rb +2 -2
- data/lib/sidekiq_bulk_job/scheduled_job.rb +7 -2
- data/lib/sidekiq_bulk_job/utils.rb +70 -56
- data/lib/sidekiq_bulk_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: e3f6ce66f186f36e576e2611b892ecbb013f888b54f27bbc36f1a463aedc7b1f
|
4
|
+
data.tar.gz: 8deff846fe66b2fa565af200678aa20a67ba0ef1550ef920fb5930da0d76bd22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1199ea0291f826b28e7eb7e3fac6c5c00e98c69d37adc46e110e567ec82977ad3519c15fada8df89b07d5237161f457ab1c71271797897eff37f7677c0e26359
|
7
|
+
data.tar.gz: 1cb8a1f0c85caa3c05c994e1412b679251293d333b9d0b30831c13130e68a480035e484d73249e7be28645e01c7f237ea9dfd5348bdb1f97e16f73375faaa144
|
data/Gemfile.lock
CHANGED
data/lib/sidekiq_bulk_job.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
1
|
+
module SidekiqBulkJob
|
2
|
+
module Utils
|
2
3
|
|
3
|
-
|
4
|
+
class << self
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
40
|
-
|
40
|
+
def constantize(camel_cased_word)
|
41
|
+
names = camel_cased_word.split("::")
|
41
42
|
|
42
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
46
|
+
# Remove the first blank element in case of '::ClassName' notation.
|
47
|
+
names.shift if names.size > 1 && names.first.empty?
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
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
|
-
|
65
|
-
|
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
|
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.
|
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-
|
11
|
+
date: 2020-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sidekiq
|