Class: Woods::Extractors::ScheduledJobExtractor
- Inherits:
-
Object
- Object
- Woods::Extractors::ScheduledJobExtractor
- Defined in:
- lib/woods/extractors/scheduled_job_extractor.rb
Overview
ScheduledJobExtractor handles scheduled/recurring job configuration extraction.
Scans three schedule file formats to extract one unit per scheduled entry:
-
‘config/recurring.yml` — Solid Queue recurring tasks
-
‘config/sidekiq_cron.yml` — Sidekiq-Cron scheduled jobs
-
‘config/schedule.rb` — Whenever DSL
Each scheduled entry becomes its own ExtractedUnit with type ‘:scheduled_job`. Identifiers are prefixed with “scheduled:” to avoid collision with JobExtractor units.
Constant Summary collapse
- SCHEDULE_FILES =
Schedule files to scan, mapped to their format
{ 'config/recurring.yml' => :solid_queue, 'config/sidekiq_cron.yml' => :sidekiq_cron, 'config/schedule.rb' => :whenever }.freeze
- CRON_HUMANIZE =
Common cron patterns mapped to human-readable descriptions
{ '* * * * *' => 'every minute', '0 * * * *' => 'every hour', '0 0 * * *' => 'daily at midnight', '0 0 * * 0' => 'weekly on Sunday', '0 0 * * 1' => 'weekly on Monday', '0 0 1 * *' => 'monthly on the 1st', '0 0 1 1 *' => 'yearly on January 1st' }.freeze
- ENVIRONMENT_KEYS =
Environment keys to unwrap when nested in YAML
%w[production development test staging].freeze
Instance Method Summary collapse
-
#extract_all ⇒ Array<ExtractedUnit>
Extract all scheduled job entries from all discovered schedule files.
-
#extract_scheduled_job_file(file_path, format = nil) ⇒ Array<ExtractedUnit>
Extract scheduled job entries from a single schedule file.
-
#initialize ⇒ ScheduledJobExtractor
constructor
A new instance of ScheduledJobExtractor.
Constructor Details
#initialize ⇒ ScheduledJobExtractor
Returns a new instance of ScheduledJobExtractor.
44 45 46 47 48 49 |
# File 'lib/woods/extractors/scheduled_job_extractor.rb', line 44 def initialize @schedule_files = SCHEDULE_FILES.each_with_object({}) do |(relative_path, format), hash| full_path = Rails.root.join(relative_path) hash[full_path.to_s] = format if File.exist?(full_path) end end |
Instance Method Details
#extract_all ⇒ Array<ExtractedUnit>
Extract all scheduled job entries from all discovered schedule files.
54 55 56 57 58 |
# File 'lib/woods/extractors/scheduled_job_extractor.rb', line 54 def extract_all @schedule_files.flat_map do |file_path, format| extract_scheduled_job_file(file_path, format) end end |
#extract_scheduled_job_file(file_path, format = nil) ⇒ Array<ExtractedUnit>
Extract scheduled job entries from a single schedule file.
Unlike other file-based extractors that return a single ExtractedUnit, this returns an Array because each schedule file contains multiple entries.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/woods/extractors/scheduled_job_extractor.rb', line 68 def extract_scheduled_job_file(file_path, format = nil) format ||= infer_format(file_path) case format when :solid_queue, :sidekiq_cron extract_yaml_schedule(file_path, format) when :whenever extract_whenever_schedule(file_path) else [] end rescue StandardError => e Rails.logger.error("Failed to extract scheduled jobs from #{file_path}: #{e.}") [] end |