chained_job 0.6.0 → 0.8.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: 4699f818627cf6babf70086a5c5d4ac5016b17bedfb48670fd262f28b2da9350
4
- data.tar.gz: 3d2f5a59e1fedaa8b11894f819739d254aa75620da658dafbb4435d1796412f1
3
+ metadata.gz: 302406755991a635c9a0e06329f3debf5ca88f3c3cf109c232b4c1c69adee53a
4
+ data.tar.gz: a61d69fc02d654c279fcede0e27ad7c6f4a29053f48604dd1edade9750b24928
5
5
  SHA512:
6
- metadata.gz: c4d6af80816570f45cc5b3e02aadb8d53f63fa10c009278401318a0a608d93d9e789038c594dedd4acd7cc54d6fd9459b13169f70d29d1687b1c82af2546e05e
7
- data.tar.gz: c4f945a8a699eeda1fa4524ba526442efa91dc83c7a5aab1485bcdda5f79c65e94d085bb706791b65262012770dd8ea85f97b6979631576ee30c8dabea8c2257
6
+ metadata.gz: 8bc2a320ddf508645c665a0636ad5b56b64be0a1d2e87549337bce7e2838115de98834fbcbae95a1efdae7e214fa2339908e149e19d9ebc82fddf5f5ef8f1d6b
7
+ data.tar.gz: b5d27297433d205f6e2ebc965c3170bef46f1bdef800287810597df564471977cf6e1c2dc73bdf587dbd53155a226c6342160a79119d55a68f6329e5451d7a11
@@ -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
@@ -17,12 +17,12 @@ module ChainedJob
17
17
  if worker_id
18
18
  ChainedJob::Process.run(args, self, job_arguments_key, worker_id, tag)
19
19
  else
20
- ChainedJob::StartChains.run(args, self.class, job_arguments_key, arguments_array, parallelism)
20
+ ChainedJob::StartChains.run(args, self.class, job_arguments_key, arguments_array(args), parallelism)
21
21
  end
22
22
  end
23
23
 
24
- def arguments_array
25
- options = { job_class: self.class }
24
+ def arguments_array(args)
25
+ options = { job_class: self.class, args: args }
26
26
  ChainedJob.config.around_array_of_job_arguments.call(options) { array_of_job_arguments }
27
27
  end
28
28
 
@@ -22,19 +22,28 @@ module ChainedJob
22
22
  with_hooks do
23
23
  return finished_worker unless argument
24
24
 
25
- job_instance.process(argument)
25
+ begin
26
+ job_instance.process(argument)
27
+ rescue StandardError => e
28
+ push_job_arguments_back if handle_retry?
29
+ raise e
30
+ end
26
31
  job_instance.class.perform_later(args, worker_id, job_tag)
27
32
  end
28
33
  end
29
34
 
30
35
  private
31
36
 
37
+ def handle_retry?
38
+ job_instance.try(:handle_retry?)
39
+ end
40
+
32
41
  def with_hooks
33
42
  ChainedJob.config.around_chain_process.call(options) { yield }
34
43
  end
35
44
 
36
45
  def options
37
- @options ||= { job_class: job_instance.class, worker_id: worker_id }
46
+ @options ||= { job_class: job_instance.class, worker_id: worker_id, args: args }
38
47
  end
39
48
 
40
49
  def finished_worker
@@ -72,5 +81,9 @@ module ChainedJob
72
81
  def job_key
73
82
  Helpers.job_key(job_arguments_key)
74
83
  end
84
+
85
+ def push_job_arguments_back
86
+ ChainedJob.redis.rpush(redis_key, Helpers.serialize([argument]))
87
+ end
75
88
  end
76
89
  end
@@ -49,6 +49,7 @@ module ChainedJob
49
49
  job_class: job_class,
50
50
  array_of_job_arguments: array_of_job_arguments,
51
51
  parallelism: parallelism,
52
+ args: args,
52
53
  }
53
54
  end
54
55
 
@@ -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)
@@ -44,10 +44,6 @@ module ChainedJob
44
44
  @job_key ||= Helpers.job_key(job_arguments_key)
45
45
  end
46
46
 
47
- def serialize(arguments)
48
- arguments.map { |argument| Marshal.dump(argument) }
49
- end
50
-
51
47
  def config
52
48
  ChainedJob.config
53
49
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChainedJob
4
- VERSION = '0.6.0'
4
+ VERSION = '0.8.0'
5
5
  end
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.6.0
4
+ version: 0.8.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-05-31 00:00:00.000000000 Z
12
+ date: 2022-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler