activejob 5.1.7 → 5.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activejob might be problematic. Click here for more details.

Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +2 -124
  3. data/README.md +1 -1
  4. data/lib/active_job.rb +2 -0
  5. data/lib/active_job/arguments.rb +3 -1
  6. data/lib/active_job/base.rb +2 -0
  7. data/lib/active_job/callbacks.rb +5 -1
  8. data/lib/active_job/configured_job.rb +2 -0
  9. data/lib/active_job/core.rb +2 -0
  10. data/lib/active_job/enqueuing.rb +3 -1
  11. data/lib/active_job/exceptions.rb +3 -1
  12. data/lib/active_job/execution.rb +2 -0
  13. data/lib/active_job/gem_version.rb +5 -3
  14. data/lib/active_job/logging.rb +3 -1
  15. data/lib/active_job/queue_adapter.rb +18 -3
  16. data/lib/active_job/queue_adapters.rb +2 -0
  17. data/lib/active_job/queue_adapters/async_adapter.rb +3 -1
  18. data/lib/active_job/queue_adapters/backburner_adapter.rb +2 -0
  19. data/lib/active_job/queue_adapters/delayed_job_adapter.rb +6 -0
  20. data/lib/active_job/queue_adapters/inline_adapter.rb +2 -0
  21. data/lib/active_job/queue_adapters/qu_adapter.rb +2 -0
  22. data/lib/active_job/queue_adapters/que_adapter.rb +2 -0
  23. data/lib/active_job/queue_adapters/queue_classic_adapter.rb +2 -0
  24. data/lib/active_job/queue_adapters/resque_adapter.rb +2 -0
  25. data/lib/active_job/queue_adapters/sidekiq_adapter.rb +2 -0
  26. data/lib/active_job/queue_adapters/sneakers_adapter.rb +2 -0
  27. data/lib/active_job/queue_adapters/sucker_punch_adapter.rb +2 -0
  28. data/lib/active_job/queue_adapters/test_adapter.rb +10 -2
  29. data/lib/active_job/queue_name.rb +6 -7
  30. data/lib/active_job/queue_priority.rb +4 -4
  31. data/lib/active_job/railtie.rb +2 -0
  32. data/lib/active_job/test_case.rb +2 -0
  33. data/lib/active_job/test_helper.rb +74 -13
  34. data/lib/active_job/translation.rb +2 -0
  35. data/lib/active_job/version.rb +2 -0
  36. data/lib/rails/generators/job/job_generator.rb +3 -1
  37. data/lib/rails/generators/job/templates/{application_job.rb → application_job.rb.tt} +0 -0
  38. data/lib/rails/generators/job/templates/{job.rb → job.rb.tt} +0 -0
  39. metadata +12 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: d82e5ced745169984f4a1c14d38bf1d6cca30b232c0f237255607523674dc847
4
- data.tar.gz: 8d1cd517a3f26399f38fa00cbb411af2818848529aec38fb63bfd101e890b090
2
+ SHA1:
3
+ metadata.gz: 5d53b499b4d5918e049d3cbb124528babab29393
4
+ data.tar.gz: 7da6adb62eed0a991b0100e5ac2da18daed2ab4c
5
5
  SHA512:
6
- metadata.gz: f89b12e696ecc88f7ea0b8755525246340b4dea66a168da5c8d1260896d25b259baeaccc4fb00c7c828aae50ce80f54519aadf0fc3440740772b74ccd8e98d5e
7
- data.tar.gz: c1234db4b8e1dddfbf72361fc44be2ca93c003fb348f3c5a6322f32a3eed51bacc7cec9fab5dfbab54aae492a8bbafd63b016d10c9d319530f8ba7110d87bde4
6
+ metadata.gz: a0b644dce5447974552e389a71a18f8acf60cb44e54bd7803a8dc238fe471a812e6db1350122fbee7ad50b863ee35edc2fecd6e83d9e64b529fe10b739c6a1d2
7
+ data.tar.gz: 6c73d5d6fbdd842278f28653a52e40a3f12440e749d915a7c7ff7b60b739c24de1bab74de7a7900309b1e3b3c1bfa4cc996b78ef3d95325c5197c7d484131379
@@ -1,129 +1,7 @@
1
- ## Rails 5.1.7 (March 27, 2019) ##
2
-
3
- * No changes.
4
-
5
-
6
- ## Rails 5.1.6.2 (March 11, 2019) ##
7
-
8
- * No changes.
9
-
10
-
11
- ## Rails 5.1.6.1 (November 27, 2018) ##
12
-
13
- * Do not deserialize GlobalID objects that were not generated by Active Job.
14
-
15
- Trusting any GlobaID object when deserializing jobs can allow attackers to access
16
- information that should not be accessible to them.
17
-
18
- Fix CVE-2018-16476.
19
-
20
- *Rafael Mendonça França*
21
-
22
-
23
- ## Rails 5.1.6 (March 29, 2018) ##
24
-
25
- * No changes.
26
-
27
-
28
- ## Rails 5.1.5 (February 14, 2018) ##
1
+ ## Rails 5.2.0.beta1 (November 27, 2017) ##
29
2
 
30
3
  * Support redis-rb 4.0.
31
4
 
32
5
  *Jeremy Daer*
33
6
 
34
-
35
- ## Rails 5.1.4 (September 07, 2017) ##
36
-
37
- * No changes.
38
-
39
-
40
- ## Rails 5.1.4.rc1 (August 24, 2017) ##
41
-
42
- * No changes.
43
-
44
-
45
- ## Rails 5.1.3 (August 03, 2017) ##
46
-
47
- * No changes.
48
-
49
-
50
- ## Rails 5.1.3.rc3 (July 31, 2017) ##
51
-
52
- * No changes.
53
-
54
-
55
- ## Rails 5.1.3.rc2 (July 25, 2017) ##
56
-
57
- * No changes.
58
-
59
-
60
- ## Rails 5.1.3.rc1 (July 19, 2017) ##
61
-
62
- * No changes.
63
-
64
-
65
- ## Rails 5.1.2 (June 26, 2017) ##
66
-
67
- * No changes.
68
-
69
-
70
- ## Rails 5.1.1 (May 12, 2017) ##
71
-
72
- * No changes.
73
-
74
-
75
- ## Rails 5.1.0 (April 27, 2017) ##
76
-
77
- * Change logging instrumentation to log errors when a job raises an exception.
78
-
79
- Fixes #26848.
80
-
81
- *Steven Bull*
82
-
83
- * Correctly set test adapter when configure the queue adapter on a per job.
84
-
85
- Fixes #26360.
86
-
87
- *Yuji Yaginuma*
88
-
89
- * Removed deprecated support to passing the adapter class to `.queue_adapter`.
90
-
91
- *Rafael Mendonça França*
92
-
93
- * Removed deprecated `#original_exception` in `ActiveJob::DeserializationError`.
94
-
95
- *Rafael Mendonça França*
96
-
97
- * Added instance variable `@queue` to JobWrapper.
98
-
99
- This will fix issues in [resque-scheduler](https://github.com/resque/resque-scheduler) `#job_to_hash` method,
100
- so we can use `#enqueue_delayed_selection`, `#remove_delayed` method in resque-scheduler smoothly.
101
-
102
- *mu29*
103
-
104
- * Yield the job instance so you have access to things like `job.arguments` on the custom logic after retries fail.
105
-
106
- *DHH*
107
-
108
- * Added declarative exception handling via `ActiveJob::Base.retry_on` and `ActiveJob::Base.discard_on`.
109
-
110
- Examples:
111
-
112
- class RemoteServiceJob < ActiveJob::Base
113
- retry_on CustomAppException # defaults to 3s wait, 5 attempts
114
- retry_on AnotherCustomAppException, wait: ->(executions) { executions * 2 }
115
- retry_on ActiveRecord::Deadlocked, wait: 5.seconds, attempts: 3
116
- retry_on Net::OpenTimeout, wait: :exponentially_longer, attempts: 10
117
- discard_on ActiveJob::DeserializationError
118
-
119
- def perform(*args)
120
- # Might raise CustomAppException or AnotherCustomAppException for something domain specific
121
- # Might raise ActiveRecord::Deadlocked when a local db deadlock is detected
122
- # Might raise Net::OpenTimeout when the remote service is down
123
- end
124
- end
125
-
126
- *DHH*
127
-
128
-
129
- Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/activejob/CHANGELOG.md) for previous changes.
7
+ Please check [5-1-stable](https://github.com/rails/rails/blob/5-1-stable/activejob/CHANGELOG.md) for previous changes.
data/README.md CHANGED
@@ -108,7 +108,7 @@ Source code can be downloaded as part of the Rails project on GitHub
108
108
 
109
109
  Active Job is released under the MIT license:
110
110
 
111
- * http://www.opensource.org/licenses/MIT
111
+ * https://opensource.org/licenses/MIT
112
112
 
113
113
 
114
114
  ## Support
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
4
  # Copyright (c) 2014-2017 David Heinemeier Hansson
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/hash"
2
4
 
3
5
  module ActiveJob
@@ -75,7 +77,7 @@ module ActiveJob
75
77
  def deserialize_argument(argument)
76
78
  case argument
77
79
  when String
78
- argument
80
+ GlobalID::Locator.locate(argument) || argument
79
81
  when *TYPE_WHITELIST
80
82
  argument
81
83
  when Array
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_job/core"
2
4
  require "active_job/queue_adapter"
3
5
  require "active_job/queue_name"
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/callbacks"
2
4
 
3
5
  module ActiveJob
4
6
  # = Active Job Callbacks
5
7
  #
6
8
  # Active Job provides hooks during the life cycle of a job. Callbacks allow you
7
- # to trigger logic during the life cycle of a job. Available callbacks are:
9
+ # to trigger logic during this cycle. Available callbacks are:
8
10
  #
9
11
  # * <tt>before_enqueue</tt>
10
12
  # * <tt>around_enqueue</tt>
@@ -13,6 +15,8 @@ module ActiveJob
13
15
  # * <tt>around_perform</tt>
14
16
  # * <tt>after_perform</tt>
15
17
  #
18
+ # NOTE: Calling the same callback multiple times will overwrite previous callback definitions.
19
+ #
16
20
  module Callbacks
17
21
  extend ActiveSupport::Concern
18
22
  include ActiveSupport::Callbacks
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveJob
2
4
  class ConfiguredJob #:nodoc:
3
5
  def initialize(job_class, options = {})
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveJob
2
4
  # Provides general behavior that will be included into every Active Job
3
5
  # object that inherits from ActiveJob::Base.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_job/arguments"
2
4
 
3
5
  module ActiveJob
@@ -8,7 +10,7 @@ module ActiveJob
8
10
  # Includes the +perform_later+ method for job initialization.
9
11
  module ClassMethods
10
12
  # Push a job onto the queue. The arguments must be legal JSON types
11
- # (string, int, float, nil, true, false, hash or array) or
13
+ # (+string+, +int+, +float+, +nil+, +true+, +false+, +hash+ or +array+) or
12
14
  # GlobalID::Identification instances. Arbitrary Ruby objects
13
15
  # are not supported.
14
16
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/numeric/time"
2
4
 
3
5
  module ActiveJob
@@ -47,7 +49,7 @@ module ActiveJob
47
49
  retry_job wait: determine_delay(wait), queue: queue, priority: priority
48
50
  else
49
51
  if block_given?
50
- yield self, exception
52
+ yield self, error
51
53
  else
52
54
  logger.error "Stopped retrying #{self.class} due to a #{exception}, which reoccurred on #{executions} attempts. The original exception was #{error.cause.inspect}."
53
55
  raise error
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/rescuable"
2
4
  require "active_job/arguments"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveJob
2
4
  # Returns the version of the currently loaded Active Job as a <tt>Gem::Version</tt>
3
5
  def self.gem_version
@@ -6,9 +8,9 @@ module ActiveJob
6
8
 
7
9
  module VERSION
8
10
  MAJOR = 5
9
- MINOR = 1
10
- TINY = 7
11
- PRE = nil
11
+ MINOR = 2
12
+ TINY = 0
13
+ PRE = "beta1"
12
14
 
13
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
14
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/hash/transform_values"
2
4
  require "active_support/core_ext/string/filters"
3
5
  require "active_support/tagged_logging"
@@ -8,7 +10,7 @@ module ActiveJob
8
10
  extend ActiveSupport::Concern
9
11
 
10
12
  included do
11
- cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
13
+ cattr_accessor :logger, default: ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))
12
14
 
13
15
  around_enqueue do |_, block, _|
14
16
  tag_logger do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/string/inflections"
2
4
 
3
5
  module ActiveJob
@@ -7,6 +9,7 @@ module ActiveJob
7
9
  extend ActiveSupport::Concern
8
10
 
9
11
  included do
12
+ class_attribute :_queue_adapter_name, instance_accessor: false, instance_predicate: false
10
13
  class_attribute :_queue_adapter, instance_accessor: false, instance_predicate: false
11
14
  self.queue_adapter = :async
12
15
  end
@@ -19,11 +22,15 @@ module ActiveJob
19
22
  _queue_adapter
20
23
  end
21
24
 
25
+ def queue_adapter_name
26
+ _queue_adapter_name
27
+ end
28
+
22
29
  # Specify the backend queue provider. The default queue adapter
23
30
  # is the +:async+ queue. See QueueAdapters for more
24
31
  # information.
25
32
  def queue_adapter=(name_or_adapter_or_class)
26
- self._queue_adapter = interpret_adapter(name_or_adapter_or_class)
33
+ interpret_adapter(name_or_adapter_or_class)
27
34
  end
28
35
 
29
36
  private
@@ -31,16 +38,24 @@ module ActiveJob
31
38
  def interpret_adapter(name_or_adapter_or_class)
32
39
  case name_or_adapter_or_class
33
40
  when Symbol, String
34
- ActiveJob::QueueAdapters.lookup(name_or_adapter_or_class).new
41
+ assign_adapter(name_or_adapter_or_class.to_s,
42
+ ActiveJob::QueueAdapters.lookup(name_or_adapter_or_class).new)
35
43
  else
36
44
  if queue_adapter?(name_or_adapter_or_class)
37
- name_or_adapter_or_class
45
+ adapter_name = "#{name_or_adapter_or_class.class.name.demodulize.remove('Adapter').underscore}"
46
+ assign_adapter(adapter_name,
47
+ name_or_adapter_or_class)
38
48
  else
39
49
  raise ArgumentError
40
50
  end
41
51
  end
42
52
  end
43
53
 
54
+ def assign_adapter(adapter_name, queue_adapter)
55
+ self._queue_adapter_name = adapter_name
56
+ self._queue_adapter = queue_adapter
57
+ end
58
+
44
59
  QUEUE_ADAPTER_METHODS = [:enqueue, :enqueue_at].freeze
45
60
 
46
61
  def queue_adapter?(object)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveJob
2
4
  # == Active Job adapters
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "securerandom"
2
4
  require "concurrent/scheduled_task"
3
5
  require "concurrent/executor/thread_pool_executor"
@@ -29,7 +31,7 @@ module ActiveJob
29
31
  # jobs. Since jobs share a single thread pool, long-running jobs will block
30
32
  # short-lived jobs. Fine for dev/test; bad for production.
31
33
  class AsyncAdapter
32
- # See {Concurrent::ThreadPoolExecutor}[http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ThreadPoolExecutor.html] for executor options.
34
+ # See {Concurrent::ThreadPoolExecutor}[https://ruby-concurrency.github.io/concurrent-ruby/Concurrent/ThreadPoolExecutor.html] for executor options.
33
35
  def initialize(**executor_options)
34
36
  @scheduler = Scheduler.new(**executor_options)
35
37
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "backburner"
2
4
 
3
5
  module ActiveJob
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "delayed_job"
2
4
 
3
5
  module ActiveJob
@@ -32,6 +34,10 @@ module ActiveJob
32
34
  @job_data = job_data
33
35
  end
34
36
 
37
+ def display_name
38
+ "#{job_data['job_class']} [#{job_data['job_id']}] from DelayedJob(#{job_data['queue_name']}) with arguments: #{job_data['arguments']}"
39
+ end
40
+
35
41
  def perform
36
42
  Base.execute(job_data)
37
43
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveJob
2
4
  module QueueAdapters
3
5
  # == Active Job Inline adapter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "qu"
2
4
 
3
5
  module ActiveJob
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "que"
2
4
 
3
5
  module ActiveJob
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "queue_classic"
2
4
 
3
5
  module ActiveJob
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "resque"
2
4
  require "active_support/core_ext/enumerable"
3
5
  require "active_support/core_ext/array/access"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "sidekiq"
2
4
 
3
5
  module ActiveJob
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "sneakers"
2
4
  require "monitor"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "sucker_punch"
2
4
 
3
5
  module ActiveJob
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveJob
2
4
  module QueueAdapters
3
5
  # == Test adapter for Active Job
@@ -10,7 +12,7 @@ module ActiveJob
10
12
  #
11
13
  # Rails.application.config.active_job.queue_adapter = :test
12
14
  class TestAdapter
13
- attr_accessor(:perform_enqueued_jobs, :perform_enqueued_at_jobs, :filter)
15
+ attr_accessor(:perform_enqueued_jobs, :perform_enqueued_at_jobs, :filter, :reject)
14
16
  attr_writer(:enqueued_jobs, :performed_jobs)
15
17
 
16
18
  # Provides a store of all the enqueued jobs with the TestAdapter so you can check them.
@@ -52,7 +54,13 @@ module ActiveJob
52
54
  end
53
55
 
54
56
  def filtered?(job)
55
- filter && !Array(filter).include?(job.class)
57
+ if filter
58
+ !Array(filter).include?(job.class)
59
+ elsif reject
60
+ Array(reject).include?(job.class)
61
+ else
62
+ false
63
+ end
56
64
  end
57
65
  end
58
66
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveJob
2
4
  module QueueName
3
5
  extend ActiveSupport::Concern
4
6
 
5
7
  # Includes the ability to override the default queue name and prefix.
6
8
  module ClassMethods
7
- mattr_accessor(:queue_name_prefix)
8
- mattr_accessor(:default_queue_name) { "default" }
9
+ mattr_accessor :queue_name_prefix
10
+ mattr_accessor :default_queue_name, default: "default"
9
11
 
10
12
  # Specifies the name of the queue to process the job on.
11
13
  #
@@ -32,11 +34,8 @@ module ActiveJob
32
34
  end
33
35
 
34
36
  included do
35
- class_attribute :queue_name, instance_accessor: false
36
- class_attribute :queue_name_delimiter, instance_accessor: false
37
-
38
- self.queue_name = default_queue_name
39
- self.queue_name_delimiter = "_" # set default delimiter to '_'
37
+ class_attribute :queue_name, instance_accessor: false, default: default_queue_name
38
+ class_attribute :queue_name_delimiter, instance_accessor: false, default: "_"
40
39
  end
41
40
 
42
41
  # Returns the name of the queue the job will be run on.
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveJob
2
4
  module QueuePriority
3
5
  extend ActiveSupport::Concern
4
6
 
5
7
  # Includes the ability to override the default queue priority.
6
8
  module ClassMethods
7
- mattr_accessor(:default_priority)
9
+ mattr_accessor :default_priority
8
10
 
9
11
  # Specifies the priority of the queue to create the job with.
10
12
  #
@@ -27,9 +29,7 @@ module ActiveJob
27
29
  end
28
30
 
29
31
  included do
30
- class_attribute :priority, instance_accessor: false
31
-
32
- self.priority = default_priority
32
+ class_attribute :priority, instance_accessor: false, default: default_priority
33
33
  end
34
34
 
35
35
  # Returns the priority that the job will be created with
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "global_id/railtie"
2
4
  require "active_job"
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/test_case"
2
4
 
3
5
  module ActiveJob
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/class/subclasses"
2
4
  require "active_support/core_ext/hash/keys"
3
5
 
@@ -87,7 +89,7 @@ module ActiveJob
87
89
  # end
88
90
  # end
89
91
  #
90
- # The number of times a specific job is enqueued can be asserted.
92
+ # The number of times a specific job was enqueued can be asserted.
91
93
  #
92
94
  # def test_logging_job
93
95
  # assert_enqueued_jobs 1, only: LoggingJob do
@@ -96,6 +98,15 @@ module ActiveJob
96
98
  # end
97
99
  # end
98
100
  #
101
+ # The number of times a job except specific class was enqueued can be asserted.
102
+ #
103
+ # def test_logging_job
104
+ # assert_enqueued_jobs 1, except: HelloJob do
105
+ # LoggingJob.perform_later
106
+ # HelloJob.perform_later('jeremy')
107
+ # end
108
+ # end
109
+ #
99
110
  # The number of times a job is enqueued to a specific queue can also be asserted.
100
111
  #
101
112
  # def test_logging_job
@@ -104,14 +115,14 @@ module ActiveJob
104
115
  # HelloJob.perform_later('elfassy')
105
116
  # end
106
117
  # end
107
- def assert_enqueued_jobs(number, only: nil, queue: nil)
118
+ def assert_enqueued_jobs(number, only: nil, except: nil, queue: nil)
108
119
  if block_given?
109
- original_count = enqueued_jobs_size(only: only, queue: queue)
120
+ original_count = enqueued_jobs_size(only: only, except: except, queue: queue)
110
121
  yield
111
- new_count = enqueued_jobs_size(only: only, queue: queue)
122
+ new_count = enqueued_jobs_size(only: only, except: except, queue: queue)
112
123
  assert_equal number, new_count - original_count, "#{number} jobs expected, but #{new_count - original_count} were enqueued"
113
124
  else
114
- actual_count = enqueued_jobs_size(only: only, queue: queue)
125
+ actual_count = enqueued_jobs_size(only: only, except: except, queue: queue)
115
126
  assert_equal number, actual_count, "#{number} jobs expected, but #{actual_count} were enqueued"
116
127
  end
117
128
  end
@@ -140,11 +151,19 @@ module ActiveJob
140
151
  # end
141
152
  # end
142
153
  #
154
+ # It can be asserted that no jobs except specific class are enqueued:
155
+ #
156
+ # def test_no_logging
157
+ # assert_no_enqueued_jobs except: HelloJob do
158
+ # HelloJob.perform_later('jeremy')
159
+ # end
160
+ # end
161
+ #
143
162
  # Note: This assertion is simply a shortcut for:
144
163
  #
145
164
  # assert_enqueued_jobs 0, &block
146
- def assert_no_enqueued_jobs(only: nil, &block)
147
- assert_enqueued_jobs 0, only: only, &block
165
+ def assert_no_enqueued_jobs(only: nil, except: nil, &block)
166
+ assert_enqueued_jobs 0, only: only, except: except, &block
148
167
  end
149
168
 
150
169
  # Asserts that the number of performed jobs matches the given number.
@@ -189,6 +208,16 @@ module ActiveJob
189
208
  # end
190
209
  # end
191
210
  #
211
+ # Also if the :except option is specified,
212
+ # then the job(s) except specific class will be performed.
213
+ #
214
+ # def test_hello_job
215
+ # assert_performed_jobs 1, except: LoggingJob do
216
+ # HelloJob.perform_later('jeremy')
217
+ # LoggingJob.perform_later
218
+ # end
219
+ # end
220
+ #
192
221
  # An array may also be specified, to support testing multiple jobs.
193
222
  #
194
223
  # def test_hello_and_logging_jobs
@@ -200,10 +229,10 @@ module ActiveJob
200
229
  # end
201
230
  # end
202
231
  # end
203
- def assert_performed_jobs(number, only: nil)
232
+ def assert_performed_jobs(number, only: nil, except: nil)
204
233
  if block_given?
205
234
  original_count = performed_jobs.size
206
- perform_enqueued_jobs(only: only) { yield }
235
+ perform_enqueued_jobs(only: only, except: except) { yield }
207
236
  new_count = performed_jobs.size
208
237
  assert_equal number, new_count - original_count,
209
238
  "#{number} jobs expected, but #{new_count - original_count} were performed"
@@ -241,11 +270,20 @@ module ActiveJob
241
270
  # end
242
271
  # end
243
272
  #
273
+ # Also if the :except option is specified,
274
+ # then the job(s) except specific class will not be performed.
275
+ #
276
+ # def test_no_logging
277
+ # assert_no_performed_jobs except: HelloJob do
278
+ # HelloJob.perform_later('jeremy')
279
+ # end
280
+ # end
281
+ #
244
282
  # Note: This assertion is simply a shortcut for:
245
283
  #
246
284
  # assert_performed_jobs 0, &block
247
- def assert_no_performed_jobs(only: nil, &block)
248
- assert_performed_jobs 0, only: only, &block
285
+ def assert_no_performed_jobs(only: nil, except: nil, &block)
286
+ assert_performed_jobs 0, only: only, except: except, &block
249
287
  end
250
288
 
251
289
  # Asserts that the job passed in the block has been enqueued with the given arguments.
@@ -315,20 +353,36 @@ module ActiveJob
315
353
  # end
316
354
  # assert_performed_jobs 1
317
355
  # end
318
- def perform_enqueued_jobs(only: nil)
356
+ #
357
+ # Also if the +:except+ option is specified,
358
+ # then the job(s) except specific class will be performed.
359
+ #
360
+ # def test_perform_enqueued_jobs_with_except
361
+ # perform_enqueued_jobs(except: HelloJob) do
362
+ # MyJob.perform_later(1, 2, 3) # will be performed
363
+ # HelloJob.perform_later(1, 2, 3) # will not be performed
364
+ # end
365
+ # assert_performed_jobs 1
366
+ # end
367
+ #
368
+ def perform_enqueued_jobs(only: nil, except: nil)
369
+ validate_option(only: only, except: except)
319
370
  old_perform_enqueued_jobs = queue_adapter.perform_enqueued_jobs
320
371
  old_perform_enqueued_at_jobs = queue_adapter.perform_enqueued_at_jobs
321
372
  old_filter = queue_adapter.filter
373
+ old_reject = queue_adapter.reject
322
374
 
323
375
  begin
324
376
  queue_adapter.perform_enqueued_jobs = true
325
377
  queue_adapter.perform_enqueued_at_jobs = true
326
378
  queue_adapter.filter = only
379
+ queue_adapter.reject = except
327
380
  yield
328
381
  ensure
329
382
  queue_adapter.perform_enqueued_jobs = old_perform_enqueued_jobs
330
383
  queue_adapter.perform_enqueued_at_jobs = old_perform_enqueued_at_jobs
331
384
  queue_adapter.filter = old_filter
385
+ queue_adapter.reject = old_reject
332
386
  end
333
387
  end
334
388
 
@@ -350,11 +404,14 @@ module ActiveJob
350
404
  performed_jobs.clear
351
405
  end
352
406
 
353
- def enqueued_jobs_size(only: nil, queue: nil)
407
+ def enqueued_jobs_size(only: nil, except: nil, queue: nil)
408
+ validate_option(only: only, except: except)
354
409
  enqueued_jobs.count do |job|
355
410
  job_class = job.fetch(:job)
356
411
  if only
357
412
  next false unless Array(only).include?(job_class)
413
+ elsif except
414
+ next false if Array(except).include?(job_class)
358
415
  end
359
416
  if queue
360
417
  next false unless queue.to_s == job.fetch(:queue, job_class.queue_name)
@@ -383,5 +440,9 @@ module ActiveJob
383
440
  klass.singleton_class.public_instance_methods(false).include?(:_queue_adapter)
384
441
  end
385
442
  end
443
+
444
+ def validate_option(only: nil, except: nil)
445
+ raise ArgumentError, "Cannot specify both `:only` and `:except` options." if only && except
446
+ end
386
447
  end
387
448
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveJob
2
4
  module Translation #:nodoc:
3
5
  extend ActiveSupport::Concern
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "gem_version"
2
4
 
3
5
  module ActiveJob
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators/named_base"
2
4
 
3
5
  module Rails # :nodoc:
@@ -12,7 +14,7 @@ module Rails # :nodoc:
12
14
  hook_for :test_framework
13
15
 
14
16
  def self.default_generator_root
15
- File.dirname(__FILE__)
17
+ __dir__
16
18
  end
17
19
 
18
20
  def create_job_file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activejob
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.7
4
+ version: 5.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-28 00:00:00.000000000 Z
11
+ date: 2017-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 5.1.7
19
+ version: 5.2.0.beta1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 5.1.7
26
+ version: 5.2.0.beta1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: globalid
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,14 +80,14 @@ files:
80
80
  - lib/active_job/translation.rb
81
81
  - lib/active_job/version.rb
82
82
  - lib/rails/generators/job/job_generator.rb
83
- - lib/rails/generators/job/templates/application_job.rb
84
- - lib/rails/generators/job/templates/job.rb
83
+ - lib/rails/generators/job/templates/application_job.rb.tt
84
+ - lib/rails/generators/job/templates/job.rb.tt
85
85
  homepage: http://rubyonrails.org
86
86
  licenses:
87
87
  - MIT
88
88
  metadata:
89
- source_code_uri: https://github.com/rails/rails/tree/v5.1.7/activejob
90
- changelog_uri: https://github.com/rails/rails/blob/v5.1.7/activejob/CHANGELOG.md
89
+ source_code_uri: https://github.com/rails/rails/tree/v5.2.0.beta1/activejob
90
+ changelog_uri: https://github.com/rails/rails/blob/v5.2.0.beta1/activejob/CHANGELOG.md
91
91
  post_install_message:
92
92
  rdoc_options: []
93
93
  require_paths:
@@ -99,11 +99,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
99
  version: 2.2.2
100
100
  required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ">="
102
+ - - ">"
103
103
  - !ruby/object:Gem::Version
104
- version: '0'
104
+ version: 1.3.1
105
105
  requirements: []
106
- rubygems_version: 3.0.1
106
+ rubyforge_project:
107
+ rubygems_version: 2.6.12
107
108
  signing_key:
108
109
  specification_version: 4
109
110
  summary: Job framework with pluggable queues.