chained_job 0.5.1 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8dd16e4b32b2941483694d35cd08b943be16d52f6277d8037276533f5d63825
4
- data.tar.gz: c082fbc66b7272971fac822d28a7eb45b68fed500094d085e5c7e1c877c375a2
3
+ metadata.gz: 4699f818627cf6babf70086a5c5d4ac5016b17bedfb48670fd262f28b2da9350
4
+ data.tar.gz: 3d2f5a59e1fedaa8b11894f819739d254aa75620da658dafbb4435d1796412f1
5
5
  SHA512:
6
- metadata.gz: 8dc323a9997040b42a8dd15f787bbc0785a7410c52e3061e13b9c1013e4526d08d597563a6b41e5663f7cb0b8941eb653116856a569b4c80f36e03a5340db624
7
- data.tar.gz: 7f3751cd2dbb44aa22646ed90434fb21e5a06e348cd575e0cbacc3525d705cab3ec7d6ebdfedd0694b21450f477813019eb590217ab7ebd4f1fc4cc59214cd2f
6
+ metadata.gz: c4d6af80816570f45cc5b3e02aadb8d53f63fa10c009278401318a0a608d93d9e789038c594dedd4acd7cc54d6fd9459b13169f70d29d1687b1c82af2546e05e
7
+ data.tar.gz: c4f945a8a699eeda1fa4524ba526442efa91dc83c7a5aab1485bcdda5f79c65e94d085bb706791b65262012770dd8ea85f97b6979631576ee30c8dabea8c2257
@@ -4,16 +4,16 @@ require 'chained_job/helpers'
4
4
 
5
5
  module ChainedJob
6
6
  class CleanUpQueue
7
- def self.run(job_class)
8
- new(job_class).run
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 :job_class
13
+ attr_reader :job_arguments_key
14
14
 
15
- def initialize(job_class)
16
- @job_class = job_class
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(job_class)
42
+ @job_key ||= Helpers.job_key(job_arguments_key)
43
43
  end
44
44
  end
45
45
  end
@@ -4,8 +4,8 @@ module ChainedJob
4
4
  module Helpers
5
5
  module_function
6
6
 
7
- def job_key(job_class)
8
- "chained_job:#{job_class}"
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)
@@ -9,11 +9,15 @@ 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, parallelism)
17
21
  end
18
22
  end
19
23
 
@@ -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
@@ -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
@@ -21,7 +23,7 @@ module ChainedJob
21
23
  return finished_worker unless argument
22
24
 
23
25
  job_instance.process(argument)
24
- job_instance.class.perform_later(worker_id, job_tag)
26
+ job_instance.class.perform_later(args, worker_id, job_tag)
25
27
  end
26
28
  end
27
29
 
@@ -68,7 +70,7 @@ module ChainedJob
68
70
  end
69
71
 
70
72
  def job_key
71
- Helpers.job_key(job_instance.class)
73
+ Helpers.job_key(job_arguments_key)
72
74
  end
73
75
  end
74
76
  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(job_class)
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(job_class, job_tag, array_of_job_arguments)
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
@@ -4,14 +4,14 @@ require 'chained_job/helpers'
4
4
 
5
5
  module ChainedJob
6
6
  class StoreJobArguments
7
- def self.run(job_class, job_tag, array_of_job_arguments)
8
- new(job_class, job_tag, array_of_job_arguments).run
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 :job_class, :job_tag, :array_of_job_arguments
11
+ attr_reader :job_arguments_key, :job_tag, :array_of_job_arguments
12
12
 
13
- def initialize(job_class, job_tag, array_of_job_arguments)
14
- @job_class = job_class
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
@@ -41,7 +41,7 @@ module ChainedJob
41
41
  end
42
42
 
43
43
  def job_key
44
- @job_key ||= Helpers.job_key(job_class)
44
+ @job_key ||= Helpers.job_key(job_arguments_key)
45
45
  end
46
46
 
47
47
  def serialize(arguments)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChainedJob
4
- VERSION = '0.5.1'
4
+ VERSION = '0.6.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.5.1
4
+ version: 0.6.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-07 00:00:00.000000000 Z
12
+ date: 2021-05-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler