-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
474d796
commit 4be5e1b
Showing
2 changed files
with
26 additions
and
15 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |