Skip to content

Instantly share code, notes, and snippets.

@tyvsmith
Created June 5, 2011 20:42
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save tyvsmith/1009401 to your computer and use it in GitHub Desktop.
Save tyvsmith/1009401 to your computer and use it in GitHub Desktop.
Dynamic changes to schedule.rb for Whenever gem
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
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