5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/serial_scheduler/runner.rb', line 5
def run(time, options = {})
daily_time_key = SerialScheduler::Converter.hour_and_minute_in_5_minute_steps(time)
weekly_time_key = SerialScheduler::Converter.weekday_hour_and_minute_in_5_minute_steps(time)
jobs = SerialScheduler::TimeTable.jobs_for([weekly_time_key, daily_time_key].compact)
jobs.each do |job|
begin
if options[:dry_run]
puts ">> #{job}"
else
SerialScheduler.logger.info("executing '#{job}'", :_job => "#{job}")
start_time = Time.now
job.call
end_time = Time.now
SerialScheduler.logger.info("successfully executed '#{job}' in #{(end_time - start_time)} seconds", :_job => "#{job}", :_execution_time => (end_time - start_time))
end
rescue => e
SerialScheduler.logger.error(e, :_job => "#{job}", :_execution_time => (start_time ? Time.now - start_time : "?"))
raise e if defined?(Rails) && Rails.env.development?
end
end
end
|