diff options
Diffstat (limited to 'activejob/lib/rails/generators')
-rw-r--r-- | activejob/lib/rails/generators/job/job_generator.rb | 22 | ||||
-rw-r--r-- | activejob/lib/rails/generators/job/templates/application_job.rb | 5 |
2 files changed, 16 insertions, 11 deletions
diff --git a/activejob/lib/rails/generators/job/job_generator.rb b/activejob/lib/rails/generators/job/job_generator.rb index 6e43e4a269..97c11a9ea6 100644 --- a/activejob/lib/rails/generators/job/job_generator.rb +++ b/activejob/lib/rails/generators/job/job_generator.rb @@ -1,13 +1,13 @@ -require 'rails/generators/named_base' +require "rails/generators/named_base" module Rails # :nodoc: module Generators # :nodoc: class JobGenerator < Rails::Generators::NamedBase # :nodoc: - desc 'This generator creates an active job file at app/jobs' + desc "This generator creates an active job file at app/jobs" - class_option :queue, type: :string, default: 'default', desc: 'The queue name for the generated job' + class_option :queue, type: :string, default: "default", desc: "The queue name for the generated job" - check_class_collision suffix: 'Job' + check_class_collision suffix: "Job" hook_for :test_framework @@ -16,22 +16,22 @@ module Rails # :nodoc: end def create_job_file - template 'job.rb', File.join('app/jobs', class_path, "#{file_name}_job.rb") + template "job.rb", File.join("app/jobs", class_path, "#{file_name}_job.rb") in_root do if self.behavior == :invoke && !File.exist?(application_job_file_name) - template 'application_job.rb', application_job_file_name + template "application_job.rb", application_job_file_name end end end private def application_job_file_name - @application_job_file_name ||= if mountable_engine? - "app/jobs/#{namespaced_path}/application_job.rb" - else - 'app/jobs/application_job.rb' - end + @application_job_file_name ||= if mountable_engine? + "app/jobs/#{namespaced_path}/application_job.rb" + else + "app/jobs/application_job.rb" + end end end end diff --git a/activejob/lib/rails/generators/job/templates/application_job.rb b/activejob/lib/rails/generators/job/templates/application_job.rb index 0b113b950e..f93745a31a 100644 --- a/activejob/lib/rails/generators/job/templates/application_job.rb +++ b/activejob/lib/rails/generators/job/templates/application_job.rb @@ -1,4 +1,9 @@ <% module_namespacing do -%> class ApplicationJob < ActiveJob::Base + # Automatically retry jobs that encountered a deadlock + # retry_on ActiveRecord::Deadlocked + + # Most jobs are safe to ignore if the underlying records are no longer available + # discard_on ActiveJob::DeserializationError end <% end -%> |