Skip to content

Commit

Permalink
rufus
Browse files Browse the repository at this point in the history
  • Loading branch information
gkostin1966 committed Jun 6, 2019
1 parent 474d796 commit 4be5e1b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
15 changes: 0 additions & 15 deletions app/schedulers/cron_scheduler.rb

This file was deleted.

26 changes: 26 additions & 0 deletions config/initializers/scheduler.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require 'rufus-scheduler'

# Let's use the rufus-scheduler singleton
scheduler = Rufus::Scheduler.singleton

# Do not schedule when Rails is run from its console, for a test/spec, or from a Rake task
return if defined?(Rails::Console) || Rails.env.test? || File.split($0).last == 'rake'

Rails.logger.info "Schedule Task #{Time.now} ..."

# Hourly - do something every hour
scheduler.every '1h' do
Rails.logger.info "Hourly #{Time.now}"
Rails.logger.flush
end

# Daily - do something every day, five minutes after midnight
# (see "man 5 crontab" in your terminal)
scheduler.cron '5 0 * * *' do
Rails.logger.info "Daily #{Time.now}"
Rails.logger.flush
end

Rails.logger.info "End Schedule Task #{Time.now}"

0 comments on commit 4be5e1b

Please sign in to comment.