Module: Gibil::Cronify

Defined in:
lib/gibil.rb

Overview

Module to write the cronjob

Class Method Summary collapse

Class Method Details

.run(file) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/gibil.rb', line 52

def self.run(file)
  if system("crontab #{file.path}")
    puts 'INFO: Wrote crontab file'
    file.unlink
    exit(0)
  else
    warn 'ERROR: Failed to write crontab'
    file.unlink
    exit(1)
  end
end

.scheduleObject

Tries to write the crontab and exits with the appropiate code



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gibil.rb', line 37

def self.schedule
  cron = <<-END.gsub(/^ {8}/, '')
    # Gibil temperature notification
    0,10,20,30,40,50 * * * * /bin/bash -l -c 'gibil job'
    # End Gibil temperature notification
  END

  require 'tempfile'
  file = Tempfile.new('temp_cronfile')
  file.write(cron)
  file.close

  run(file)
end

.temp_path(cron) ⇒ Object



64
65
66
# File 'lib/gibil.rb', line 64

def self.temp_path(cron)
  file.path
end