diff options
Diffstat (limited to 'activejob/lib/rails/generators')
-rw-r--r-- | activejob/lib/rails/generators/job/job_generator.rb | 25 | ||||
-rw-r--r-- | activejob/lib/rails/generators/job/templates/application_job.rb | 9 |
2 files changed, 29 insertions, 5 deletions
diff --git a/activejob/lib/rails/generators/job/job_generator.rb b/activejob/lib/rails/generators/job/job_generator.rb index 2115fb9f71..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,8 +16,23 @@ 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 + 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 + 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 new file mode 100644 index 0000000000..f93745a31a --- /dev/null +++ b/activejob/lib/rails/generators/job/templates/application_job.rb @@ -0,0 +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 -%> |