diff options
Diffstat (limited to 'activejob')
-rw-r--r-- | activejob/CHANGELOG.md | 6 | ||||
-rw-r--r-- | activejob/Rakefile | 4 | ||||
-rw-r--r-- | activejob/lib/active_job/core.rb | 20 | ||||
-rw-r--r-- | activejob/lib/active_job/exceptions.rb | 10 | ||||
-rw-r--r-- | activejob/lib/active_job/queue_adapters.rb | 2 | ||||
-rw-r--r-- | activejob/lib/rails/generators/job/job_generator.rb | 4 | ||||
-rw-r--r-- | activejob/test/cases/exceptions_test.rb | 2 | ||||
-rw-r--r-- | activejob/test/cases/job_serialization_test.rb | 12 | ||||
-rw-r--r-- | activejob/test/jobs/retry_job.rb | 4 |
9 files changed, 43 insertions, 21 deletions
diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md index a3d13ad162..dcb9d27f45 100644 --- a/activejob/CHANGELOG.md +++ b/activejob/CHANGELOG.md @@ -1,3 +1,9 @@ +* Pass the error instance as the second parameter of block executed by `discard_on`. + + Fixes #32853. + + *Yuji Yaginuma* + * Remove support for Qu gem. Reasons are that the Qu gem wasn't compatible since Rails 5.1, diff --git a/activejob/Rakefile b/activejob/Rakefile index b4da75adab..0f88b22e8d 100644 --- a/activejob/Rakefile +++ b/activejob/Rakefile @@ -38,7 +38,7 @@ namespace :test do t.libs << "test" t.test_files = FileList["test/cases/**/*_test.rb"] t.verbose = true - t.warning = false + t.warning = true t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION) end @@ -56,7 +56,7 @@ namespace :test do t.libs << "test" t.test_files = FileList["test/integration/**/*_test.rb"] t.verbose = true - t.warning = false + t.warning = true t.ruby_opts = ["--dev"] if defined?(JRUBY_VERSION) end end diff --git a/activejob/lib/active_job/core.rb b/activejob/lib/active_job/core.rb index da841ae45b..61d402cfca 100644 --- a/activejob/lib/active_job/core.rb +++ b/activejob/lib/active_job/core.rb @@ -88,7 +88,7 @@ module ActiveJob "provider_job_id" => provider_job_id, "queue_name" => queue_name, "priority" => priority, - "arguments" => serialize_arguments(arguments), + "arguments" => serialize_arguments_if_needed(arguments), "executions" => executions, "locale" => I18n.locale.to_s, "timezone" => Time.zone.try(:name) @@ -133,19 +133,31 @@ module ActiveJob end private + def serialize_arguments_if_needed(arguments) + if arguments_serialized? + @serialized_arguments + else + serialize_arguments(arguments) + end + end + def deserialize_arguments_if_needed - if defined?(@serialized_arguments) && @serialized_arguments.present? + if arguments_serialized? @arguments = deserialize_arguments(@serialized_arguments) @serialized_arguments = nil end end - def serialize_arguments(serialized_args) - Arguments.serialize(serialized_args) + def serialize_arguments(arguments) + Arguments.serialize(arguments) end def deserialize_arguments(serialized_args) Arguments.deserialize(serialized_args) end + + def arguments_serialized? + defined?(@serialized_arguments) && @serialized_arguments + end end end diff --git a/activejob/lib/active_job/exceptions.rb b/activejob/lib/active_job/exceptions.rb index ae700848d0..96b1e262f2 100644 --- a/activejob/lib/active_job/exceptions.rb +++ b/activejob/lib/active_job/exceptions.rb @@ -30,8 +30,8 @@ module ActiveJob # class RemoteServiceJob < ActiveJob::Base # retry_on CustomAppException # defaults to 3s wait, 5 attempts # retry_on AnotherCustomAppException, wait: ->(executions) { executions * 2 } - # retry_on(YetAnotherCustomAppException) do |job, exception| - # ExceptionNotifier.caught(exception) + # retry_on(YetAnotherCustomAppException) do |job, error| + # ExceptionNotifier.caught(error) # end # retry_on ActiveRecord::Deadlocked, wait: 5.seconds, attempts: 3 # retry_on Net::OpenTimeout, wait: :exponentially_longer, attempts: 10 @@ -67,8 +67,8 @@ module ActiveJob # # class SearchIndexingJob < ActiveJob::Base # discard_on ActiveJob::DeserializationError - # discard_on(CustomAppException) do |job, exception| - # ExceptionNotifier.caught(exception) + # discard_on(CustomAppException) do |job, error| + # ExceptionNotifier.caught(error) # end # # def perform(record) @@ -79,7 +79,7 @@ module ActiveJob def discard_on(exception) rescue_from exception do |error| if block_given? - yield self, exception + yield self, error else logger.error "Discarded #{self.class} due to a #{exception}. The original exception was #{error.cause.inspect}." end diff --git a/activejob/lib/active_job/queue_adapters.rb b/activejob/lib/active_job/queue_adapters.rb index 7854467cc1..00c7b407b1 100644 --- a/activejob/lib/active_job/queue_adapters.rb +++ b/activejob/lib/active_job/queue_adapters.rb @@ -15,7 +15,7 @@ module ActiveJob # * {Sucker Punch}[https://github.com/brandonhilkert/sucker_punch] # * {Active Job Async Job}[http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters/AsyncAdapter.html] # * {Active Job Inline}[http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters/InlineAdapter.html] - # * Please Note: We are not accepting pull requests for new adapters. See the README for more details. + # * Please Note: We are not accepting pull requests for new adapters. See the {README}[link:files/activejob/README_md.html] for more details. # # === Backends Features # diff --git a/activejob/lib/rails/generators/job/job_generator.rb b/activejob/lib/rails/generators/job/job_generator.rb index 69b4fe7d26..03346a7f12 100644 --- a/activejob/lib/rails/generators/job/job_generator.rb +++ b/activejob/lib/rails/generators/job/job_generator.rb @@ -28,6 +28,10 @@ module Rails # :nodoc: end private + def file_name + @_file_name ||= super.sub(/_job\z/i, "") + end + def application_job_file_name @application_job_file_name ||= if mountable_engine? "app/jobs/#{namespaced_path}/application_job.rb" diff --git a/activejob/test/cases/exceptions_test.rb b/activejob/test/cases/exceptions_test.rb index bc33d79f61..15938e3fc7 100644 --- a/activejob/test/cases/exceptions_test.rb +++ b/activejob/test/cases/exceptions_test.rb @@ -61,7 +61,7 @@ class ExceptionsTest < ActiveJob::TestCase test "custom handling of discarded job" do perform_enqueued_jobs do RetryJob.perform_later "CustomDiscardableError", 2 - assert_equal "Dealt with a job that was discarded in a custom way", JobBuffer.last_value + assert_equal "Dealt with a job that was discarded in a custom way. Message: CustomDiscardableError", JobBuffer.last_value end end diff --git a/activejob/test/cases/job_serialization_test.rb b/activejob/test/cases/job_serialization_test.rb index 5c9994508e..86f3651564 100644 --- a/activejob/test/cases/job_serialization_test.rb +++ b/activejob/test/cases/job_serialization_test.rb @@ -23,16 +23,16 @@ class JobSerializationTest < ActiveSupport::TestCase test "serialize and deserialize are symmetric" do # Round trip a job in memory only - h1 = HelloJob.new - h1.deserialize(h1.serialize) + h1 = HelloJob.new("Rafael") + h2 = HelloJob.deserialize(h1.serialize) + assert_equal h1.serialize, h2.serialize # Now verify it's identical to a JSON round trip. # We don't want any non-native JSON elements in the job hash, # like symbols. - payload = JSON.dump(h1.serialize) - h2 = HelloJob.new - h2.deserialize(JSON.load(payload)) - assert_equal h1.serialize, h2.serialize + payload = JSON.dump(h2.serialize) + h3 = HelloJob.deserialize(JSON.load(payload)) + assert_equal h2.serialize, h3.serialize end test "deserialize sets locale" do diff --git a/activejob/test/jobs/retry_job.rb b/activejob/test/jobs/retry_job.rb index 82b80fe12b..a12c65015b 100644 --- a/activejob/test/jobs/retry_job.rb +++ b/activejob/test/jobs/retry_job.rb @@ -18,9 +18,9 @@ class RetryJob < ActiveJob::Base retry_on ShortWaitTenAttemptsError, wait: 1.second, attempts: 10 retry_on ExponentialWaitTenAttemptsError, wait: :exponentially_longer, attempts: 10 retry_on CustomWaitTenAttemptsError, wait: ->(executions) { executions * 2 }, attempts: 10 - retry_on(CustomCatchError) { |job, exception| JobBuffer.add("Dealt with a job that failed to retry in a custom way after #{job.arguments.second} attempts. Message: #{exception.message}") } + retry_on(CustomCatchError) { |job, error| JobBuffer.add("Dealt with a job that failed to retry in a custom way after #{job.arguments.second} attempts. Message: #{error.message}") } discard_on DiscardableError - discard_on(CustomDiscardableError) { |job, exception| JobBuffer.add("Dealt with a job that was discarded in a custom way") } + discard_on(CustomDiscardableError) { |job, error| JobBuffer.add("Dealt with a job that was discarded in a custom way. Message: #{error.message}") } def perform(raising, attempts) if executions < attempts |