Skip to content

Instantly share code, notes, and snippets.

@rishiip
Last active September 12, 2019 18:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rishiip/ebced57ddede09248d7230cbaf9fac80 to your computer and use it in GitHub Desktop.
config/schedule.rb
# config/schedule.rb
# Send daily sales report at 9:00 am everyday.
every 1.day, at: '9:00 am' do
rake 'send_daily_sales_report'
end
# to run the cron in 10 to 7 IST timings.
every 1.hour, at: ['4:30 am', '5:30 am', '6:30 am', '7:30 am', '8:30 am', '9:30 am', '10:30 am', '11:30 am', '12:30 pm', '1:30 pm'] do
runner 'UtilitiesService.clean_logs()'
end
# Convert IST to UTC and return array of UTC time like ['2:30 am', '3:30 am',...]
def to_utc(*time)
begin
time.collect{ |t| ActiveSupport::TimeZone.new('Mumbai').local_to_utc(Time.parse(t)).strftime('%l:%M %P').strip }
rescue Exception => e
Rails.logger.info "Error: #{e.message}"
Rails.logger.info "Backtrace: #{e.backtrace}"
end
end
# to run the cron in 10 to 7 IST timings.
every 1.hour, at: to_utc('10:00 am', '11:00 am', '12:00 pm', '1:00 pm', '2:00 pm', '3:00 pm', '4:00 pm', '5:00 pm', '6:00 pm', '7:00 pm') do
runner 'UtilitiesService.clean_logs()'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment