class Gleis::Scheduler

The class implements the methods required to manage the scheduler service of a Gleis app

Public Class Methods

add(app_name, frequency, time, command) click to toggle source
# File lib/gleis/scheduler.rb, line 4
def self.add(app_name, frequency, time, command)
  token = Token.check
  body = API.request('post', 'scheduler', token, 'name': app_name, 'frequency': frequency, 'time': time,
                                                 'command': command)
  if body['success'] == 1
    puts "Successfully added scheduler job to #{app_name}."
  else
    puts "Failed to add scheduler job: #{body['message']}"
  end
end
list(app_name) click to toggle source
# File lib/gleis/scheduler.rb, line 15
def self.list(app_name)
  token = Token.check
  body = API.request('get', "scheduler/#{app_name}", token)
  jobs = body ['data']
  if jobs.first.empty?
    puts 'No scheduled jobs.'
  else
    puts "List of scheduled jobs:\n\n"
    printf("\t%s\n", 'TIME')
    printf("\t%-30s %-15s %s\n", 'COMMAND', 'FREQUENCY', 'LAST RUN')
    printf("\t%-30s %-15s %s\n\n", '-------', '---------', '--------')
    jobs.each do |job|
      last_run = job['last_run'] ? Time.parse(job['last_run']).localtime.strftime('%c') : 'never'
      printf("\t%-30s %-15s %s\n", job['cron_time'], job['frequency'], last_run)
      puts "\t#{job['command']}\n\n"
    end
  end
end
remove(app_name) click to toggle source
# File lib/gleis/scheduler.rb, line 34
def self.remove(app_name)
  token = Token.check
  body = API.request('delete', "scheduler/#{app_name}", token)
  if body['success'] == 1
    puts "Successfully removed scheduled job from #{app_name}."
  else
    puts "Failed to remove scheduled job: #{body['message']}"
  end
end