Class: MultiserverWhenever
- Inherits:
-
Object
- Object
- MultiserverWhenever
- Defined in:
- lib/multiserver_whenever.rb
Instance Method Summary collapse
- #clear! ⇒ Object
- #config ⇒ Object
- #current_whenever_identifiers ⇒ Object
-
#dummy_whenever_path ⇒ Object
So for some reason, the whenever command requires that the –load-file argument be passed, even if you are using the –clear-crontab argument to clear out outdated crontabs.
- #hostname ⇒ Object
-
#initialize(set_vars = {}) ⇒ MultiserverWhenever
constructor
A new instance of MultiserverWhenever.
-
#parse_identifiers ⇒ Object
Only worry about whenever blocks for this project.
- #read_config ⇒ Object
- #read_cron ⇒ Object
- #roles ⇒ Object
- #write! ⇒ Object
Constructor Details
#initialize(set_vars = {}) ⇒ MultiserverWhenever
Returns a new instance of MultiserverWhenever.
4 5 6 7 |
# File 'lib/multiserver_whenever.rb', line 4 def initialize(set_vars = {}) defaults = {:environment => 'production'} @set_vars = defaults.merge(set_vars) end |
Instance Method Details
#clear! ⇒ Object
9 10 11 12 13 |
# File 'lib/multiserver_whenever.rb', line 9 def clear! current_whenever_identifiers.each do |identifier| whenever_with_vars "--load-file #{dummy_whenever_path} --clear-crontab #{identifier}" end end |
#config ⇒ Object
35 36 37 |
# File 'lib/multiserver_whenever.rb', line 35 def config @config ||= YAML.load(read_config) end |
#current_whenever_identifiers ⇒ Object
23 24 25 |
# File 'lib/multiserver_whenever.rb', line 23 def current_whenever_identifiers @identifiers ||= parse_identifiers end |
#dummy_whenever_path ⇒ Object
So for some reason, the whenever command requires that the –load-file argument be passed, even if you are using the –clear-crontab argument to clear out outdated crontabs.
The problem is that you may need to clear out old crontab data from cron that was generated by a whenever file that no longer exists, so you can’t use it for the –load-file argument. As it’s unnecessary anyways, I’m just going to use the config/whenever/do_not_remove.rb file anytime we’re clearing crontabs out. It’s an “empty” file, but we need to keep it around.
59 60 61 |
# File 'lib/multiserver_whenever.rb', line 59 def dummy_whenever_path "config/whenever/do_not_remove.rb" end |
#hostname ⇒ Object
43 44 45 |
# File 'lib/multiserver_whenever.rb', line 43 def hostname command('hostname') end |
#parse_identifiers ⇒ Object
Only worry about whenever blocks for this project
64 65 66 67 68 69 70 |
# File 'lib/multiserver_whenever.rb', line 64 def parse_identifiers lines = read_cron.split("\n") root_dir = Dir.pwd puts "Root Dir is : #{root_dir}" lines = lines.select {|line| line =~ /^# Begin Whenever generated tasks for: #{root_dir}/ } lines.map {|line| line.gsub("# Begin Whenever generated tasks for: ", '') } end |
#read_config ⇒ Object
39 40 41 |
# File 'lib/multiserver_whenever.rb', line 39 def read_config File.read("config/whenever.yml") end |
#read_cron ⇒ Object
27 28 29 |
# File 'lib/multiserver_whenever.rb', line 27 def read_cron command("crontab -l") end |
#roles ⇒ Object
31 32 33 |
# File 'lib/multiserver_whenever.rb', line 31 def roles [config[hostname]].flatten.compact end |
#write! ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/multiserver_whenever.rb', line 15 def write! roles.each do |role| relative_path = "config/whenever/#{role}.rb" absolute_path = File.(relative_path) whenever_with_vars "--load-file #{relative_path} --update-crontab #{absolute_path}" end end |