Class: PgCron::Generators::JobGenerator Private
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- PgCron::Generators::JobGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/pg_cron/job/job_generator.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Generates a cron job definition and its migration.
rails generate pg_cron:job drain_juicefs_events
Structured exactly as Fx::Generators::FunctionGenerator: the same class_option, the same three phases (directory, definition, migration), and the same versioning behaviour — running it again for an existing job COPIES the previous definition to the next version rather than creating an empty file, so an edit starts from what is currently deployed and the migration it writes is an update with revert_to_version set.
Constant Summary collapse
- DEFINITION_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%w[db cron].freeze
Class Method Summary collapse
Instance Method Summary collapse
- #create_cron_directory ⇒ Object private
- #create_job_definition ⇒ Object private
- #create_migration_file ⇒ Object private
Class Method Details
.next_migration_number(dir) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
61 62 63 |
# File 'lib/generators/pg_cron/job/job_generator.rb', line 61 def self.next_migration_number(dir) ::ActiveRecord::Generators::Base.next_migration_number(dir) end |
Instance Method Details
#create_cron_directory ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 35 36 |
# File 'lib/generators/pg_cron/job/job_generator.rb', line 32 def create_cron_directory return if job_definition_path.exist? empty_directory(job_definition_path) end |
#create_job_definition ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
38 39 40 41 42 43 44 |
# File 'lib/generators/pg_cron/job/job_generator.rb', line 38 def create_job_definition if version_helper.creating_new? create_file(definition.path) else copy_file(previous_definition.full_path, definition.full_path) end end |
#create_migration_file ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/generators/pg_cron/job/job_generator.rb', line 46 def create_migration_file return if migration_helper.skip_creation? template_info = migration_helper.migration_template_info( file_name: file_name, updating_existing: version_helper.updating_existing?, version: version_helper.current_version ) migration_template( template_info.fetch(:template), template_info.fetch(:filename) ) end |