Created
June 5, 2011 20:42
-
-
Save tyvsmith/1009401 to your computer and use it in GitHub Desktop.
Dynamic changes to schedule.rb for Whenever gem
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
require File.expand_path('../config/environment', __FILE__) | |
upload_interval = Setting.for('FTP Update Interval').value || 15 | |
every upload_interval.to_i.minutes do | |
runner 'Device.upload_csv_to_ftp' | |
end |
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
class Setting < ActiveRecord::Base | |
validates_uniqueness_of :var | |
validates_presence_of :value | |
after_save :send_cron_later | |
#Setting.for(:display).set=(value) | |
def self.for(var) | |
find_or_create_by_var(var) | |
end | |
def set=(value) | |
update_attributes(:value => value) | |
end | |
def send_cron_later | |
#Using delayed job to run this later to not hold up an HTTP thread. | |
delay.update_cron if var.eql?("FTP Update Interval") | |
end | |
def update_cron | |
system 'bundle exec whenever --update-crontab store' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment