Class: JobTick::Parsers::Whenever

Inherits:
Object
  • Object
show all
Defined in:
lib/jobtick/parsers/whenever.rb

Constant Summary collapse

SCHEDULE_FILE =
"config/schedule.rb"

Class Method Summary collapse

Class Method Details

.parseObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jobtick/parsers/whenever.rb', line 8

def self.parse
  return [] unless defined?(::Whenever)
  return [] unless File.exist?(SCHEDULE_FILE)

  schedule = ::Whenever::JobList.new(file: SCHEDULE_FILE)
  schedule.jobs.flat_map do |period, jobs|
    jobs.map do |job|
      {
        key: job_key(job),
        schedule: period.to_s,
        source: "whenever",
        task: job[:task].to_s.strip
      }
    end
  end
rescue StandardError => e
  JobTick.logger.warn("[JobTick] Whenever parser failed: #{e.message}")
  []
end