chained_job 0.5.0 → 0.7.0
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 +4 -4
- data/lib/chained_job/clean_up_queue.rb +6 -6
- data/lib/chained_job/helpers.rb +6 -2
- data/lib/chained_job/middleware.rb +13 -5
- data/lib/chained_job/process.rb +25 -11
- data/lib/chained_job/start_chains.rb +10 -7
- data/lib/chained_job/store_job_arguments.rb +7 -11
- data/lib/chained_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: 627fdbd88729785e5f036aa8eead67eba9e829ab8fff3fa7d7792249a9dcea0e
|
4
|
+
data.tar.gz: d3e9721bfae1f4676428d73a3efba5c417c89527f2750de10ef859c0846e567e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cadabdd000cb69d656b930d0ad960af23901634c02725e6299669aa963ec9e0d732b98d6adce7785d1b1f37b8e0bab4453fa7b6ed558dbe208d7bbe07d3a7d95
|
7
|
+
data.tar.gz: c1b8e3ed98fe248078ac19bcc07db5c0a04bd2b747fb6b88f43698835a6da805db33b7b36685d5a38432fc42613e329418080035e564b1b95c56c946b9cafc5f
|
@@ -4,16 +4,16 @@ require 'chained_job/helpers'
|
|
4
4
|
|
5
5
|
module ChainedJob
|
6
6
|
class CleanUpQueue
|
7
|
-
def self.run(
|
8
|
-
new(
|
7
|
+
def self.run(job_arguments_key)
|
8
|
+
new(job_arguments_key).run
|
9
9
|
end
|
10
10
|
|
11
11
|
TRIM_STEP_SIZE = 1_000
|
12
12
|
|
13
|
-
attr_reader :
|
13
|
+
attr_reader :job_arguments_key
|
14
14
|
|
15
|
-
def initialize(
|
16
|
-
@
|
15
|
+
def initialize(job_arguments_key)
|
16
|
+
@job_arguments_key = job_arguments_key
|
17
17
|
end
|
18
18
|
|
19
19
|
# rubocop:disable Metrics/AbcSize
|
@@ -39,7 +39,7 @@ module ChainedJob
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def job_key
|
42
|
-
@job_key ||= Helpers.job_key(
|
42
|
+
@job_key ||= Helpers.job_key(job_arguments_key)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
data/lib/chained_job/helpers.rb
CHANGED
@@ -4,8 +4,8 @@ module ChainedJob
|
|
4
4
|
module Helpers
|
5
5
|
module_function
|
6
6
|
|
7
|
-
def job_key(
|
8
|
-
"chained_job:#{
|
7
|
+
def job_key(job_arguments_key)
|
8
|
+
"chained_job:#{job_arguments_key}"
|
9
9
|
end
|
10
10
|
|
11
11
|
def redis_key(job_key, tag)
|
@@ -15,5 +15,9 @@ module ChainedJob
|
|
15
15
|
def tag_list(prefix)
|
16
16
|
"#{prefix}:tags"
|
17
17
|
end
|
18
|
+
|
19
|
+
def serialize(arguments)
|
20
|
+
arguments.map { |argument| Marshal.dump(argument) }
|
21
|
+
end
|
18
22
|
end
|
19
23
|
end
|
@@ -9,16 +9,20 @@ module ChainedJob
|
|
9
9
|
base.queue_as ChainedJob.config.queue if ChainedJob.config.queue
|
10
10
|
end
|
11
11
|
|
12
|
-
def perform(worker_id = nil, tag = nil)
|
12
|
+
def perform(args = {}, worker_id = nil, tag = nil)
|
13
|
+
unless Hash === args
|
14
|
+
# backward compatibility
|
15
|
+
args, worker_id, tag = {}, args, worker_id
|
16
|
+
end
|
13
17
|
if worker_id
|
14
|
-
ChainedJob::Process.run(self, worker_id, tag)
|
18
|
+
ChainedJob::Process.run(args, self, job_arguments_key, worker_id, tag)
|
15
19
|
else
|
16
|
-
ChainedJob::StartChains.run(self.class, arguments_array, parallelism)
|
20
|
+
ChainedJob::StartChains.run(args, self.class, job_arguments_key, arguments_array(args), parallelism)
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
20
|
-
def arguments_array
|
21
|
-
options = { job_class: self.class }
|
24
|
+
def arguments_array(args)
|
25
|
+
options = { job_class: self.class, args: args }
|
22
26
|
ChainedJob.config.around_array_of_job_arguments.call(options) { array_of_job_arguments }
|
23
27
|
end
|
24
28
|
|
@@ -29,5 +33,9 @@ module ChainedJob
|
|
29
33
|
def parallelism
|
30
34
|
raise NoMethodError, 'undefined method parallelism'
|
31
35
|
end
|
36
|
+
|
37
|
+
def job_arguments_key
|
38
|
+
self.class
|
39
|
+
end
|
32
40
|
end
|
33
41
|
end
|
data/lib/chained_job/process.rb
CHANGED
@@ -4,14 +4,16 @@ require 'chained_job/helpers'
|
|
4
4
|
|
5
5
|
module ChainedJob
|
6
6
|
class Process
|
7
|
-
def self.run(job_instance, worker_id, job_tag)
|
8
|
-
new(job_instance, worker_id, job_tag).run
|
7
|
+
def self.run(args, job_instance, job_arguments_key, worker_id, job_tag)
|
8
|
+
new(args, job_instance, job_arguments_key, worker_id, job_tag).run
|
9
9
|
end
|
10
10
|
|
11
|
-
attr_reader :job_instance, :worker_id, :job_tag
|
11
|
+
attr_reader :args, :job_instance, :job_arguments_key, :worker_id, :job_tag
|
12
12
|
|
13
|
-
def initialize(job_instance, worker_id, job_tag)
|
13
|
+
def initialize(args, job_instance, job_arguments_key, worker_id, job_tag)
|
14
|
+
@args = args
|
14
15
|
@job_instance = job_instance
|
16
|
+
@job_arguments_key = job_arguments_key
|
15
17
|
@worker_id = worker_id
|
16
18
|
@job_tag = job_tag
|
17
19
|
end
|
@@ -20,19 +22,28 @@ module ChainedJob
|
|
20
22
|
with_hooks do
|
21
23
|
return finished_worker unless argument
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
begin
|
26
|
+
job_instance.process(argument)
|
27
|
+
rescue StandardError => e
|
28
|
+
push_job_arguments_back if handle_retry?
|
29
|
+
raise e
|
30
|
+
end
|
31
|
+
job_instance.class.perform_later(args, worker_id, job_tag)
|
25
32
|
end
|
26
33
|
end
|
27
34
|
|
28
35
|
private
|
29
36
|
|
37
|
+
def handle_retry?
|
38
|
+
job_instance.try(:handle_retry?)
|
39
|
+
end
|
40
|
+
|
30
41
|
def with_hooks
|
31
42
|
ChainedJob.config.around_chain_process.call(options) { yield }
|
32
43
|
end
|
33
44
|
|
34
45
|
def options
|
35
|
-
@options ||= { job_class: job_instance.class, worker_id: worker_id }
|
46
|
+
@options ||= { job_class: job_instance.class, worker_id: worker_id, args: args }
|
36
47
|
end
|
37
48
|
|
38
49
|
def finished_worker
|
@@ -52,10 +63,9 @@ module ChainedJob
|
|
52
63
|
end
|
53
64
|
|
54
65
|
def deserialized_argument
|
66
|
+
return unless serialized_argument
|
67
|
+
|
55
68
|
Marshal.load(serialized_argument)
|
56
|
-
rescue TypeError, ArgumentError
|
57
|
-
# backward compatibility
|
58
|
-
serialized_argument
|
59
69
|
end
|
60
70
|
|
61
71
|
def serialized_argument
|
@@ -69,7 +79,11 @@ module ChainedJob
|
|
69
79
|
end
|
70
80
|
|
71
81
|
def job_key
|
72
|
-
Helpers.job_key(
|
82
|
+
Helpers.job_key(job_arguments_key)
|
83
|
+
end
|
84
|
+
|
85
|
+
def push_job_arguments_back
|
86
|
+
ChainedJob.redis.rpush(redis_key, Helpers.serialize([argument]))
|
73
87
|
end
|
74
88
|
end
|
75
89
|
end
|
@@ -6,14 +6,16 @@ require 'chained_job/store_job_arguments'
|
|
6
6
|
|
7
7
|
module ChainedJob
|
8
8
|
class StartChains
|
9
|
-
def self.run(job_class, array_of_job_arguments, parallelism)
|
10
|
-
new(job_class, array_of_job_arguments, parallelism).run
|
9
|
+
def self.run(args, job_class, job_arguments_key, array_of_job_arguments, parallelism)
|
10
|
+
new(args, job_class, job_arguments_key, array_of_job_arguments, parallelism).run
|
11
11
|
end
|
12
12
|
|
13
|
-
attr_reader :job_class, :array_of_job_arguments, :parallelism
|
13
|
+
attr_reader :args, :job_class, :job_arguments_key, :array_of_job_arguments, :parallelism
|
14
14
|
|
15
|
-
def initialize(job_class, array_of_job_arguments, parallelism)
|
15
|
+
def initialize(args, job_class, job_arguments_key, array_of_job_arguments, parallelism)
|
16
|
+
@args = args
|
16
17
|
@job_class = job_class
|
18
|
+
@job_arguments_key = job_arguments_key
|
17
19
|
@array_of_job_arguments = array_of_job_arguments
|
18
20
|
@parallelism = parallelism
|
19
21
|
end
|
@@ -23,15 +25,15 @@ module ChainedJob
|
|
23
25
|
with_hooks do
|
24
26
|
log_chained_job_cleanup
|
25
27
|
|
26
|
-
ChainedJob::CleanUpQueue.run(
|
28
|
+
ChainedJob::CleanUpQueue.run(job_arguments_key)
|
27
29
|
|
28
30
|
next unless array_of_job_arguments.count.positive?
|
29
31
|
|
30
|
-
ChainedJob::StoreJobArguments.run(
|
32
|
+
ChainedJob::StoreJobArguments.run(job_arguments_key, job_tag, array_of_job_arguments)
|
31
33
|
|
32
34
|
log_chained_job_start
|
33
35
|
|
34
|
-
parallelism.times { |worked_id| job_class.perform_later(worked_id, job_tag) }
|
36
|
+
parallelism.times { |worked_id| job_class.perform_later(args, worked_id, job_tag) }
|
35
37
|
end
|
36
38
|
end
|
37
39
|
# rubocop:enable Metrics/AbcSize
|
@@ -47,6 +49,7 @@ module ChainedJob
|
|
47
49
|
job_class: job_class,
|
48
50
|
array_of_job_arguments: array_of_job_arguments,
|
49
51
|
parallelism: parallelism,
|
52
|
+
args: args,
|
50
53
|
}
|
51
54
|
end
|
52
55
|
|
@@ -4,14 +4,14 @@ require 'chained_job/helpers'
|
|
4
4
|
|
5
5
|
module ChainedJob
|
6
6
|
class StoreJobArguments
|
7
|
-
def self.run(
|
8
|
-
new(
|
7
|
+
def self.run(job_arguments_key, job_tag, array_of_job_arguments)
|
8
|
+
new(job_arguments_key, job_tag, array_of_job_arguments).run
|
9
9
|
end
|
10
10
|
|
11
|
-
attr_reader :
|
11
|
+
attr_reader :job_arguments_key, :job_tag, :array_of_job_arguments
|
12
12
|
|
13
|
-
def initialize(
|
14
|
-
@
|
13
|
+
def initialize(job_arguments_key, job_tag, array_of_job_arguments)
|
14
|
+
@job_arguments_key = job_arguments_key
|
15
15
|
@job_tag = job_tag
|
16
16
|
@array_of_job_arguments = array_of_job_arguments
|
17
17
|
end
|
@@ -20,7 +20,7 @@ module ChainedJob
|
|
20
20
|
set_tag_list
|
21
21
|
|
22
22
|
array_of_job_arguments.each_slice(config.arguments_batch_size) do |sublist|
|
23
|
-
ChainedJob.redis.rpush(redis_key, serialize(sublist))
|
23
|
+
ChainedJob.redis.rpush(redis_key, Helpers.serialize(sublist))
|
24
24
|
end
|
25
25
|
|
26
26
|
ChainedJob.redis.expire(redis_key, config.arguments_queue_expiration)
|
@@ -41,11 +41,7 @@ module ChainedJob
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def job_key
|
44
|
-
@job_key ||= Helpers.job_key(
|
45
|
-
end
|
46
|
-
|
47
|
-
def serialize(arguments)
|
48
|
-
arguments.map { |argument| Marshal.dump(argument) }
|
44
|
+
@job_key ||= Helpers.job_key(job_arguments_key)
|
49
45
|
end
|
50
46
|
|
51
47
|
def config
|
data/lib/chained_job/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chained_job
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mantas Kūjalis
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-08-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|