Class: CronKubernetes::Scheduler

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/cron_kubernetes/scheduler.rb

Overview

A singleton that creates and holds the scheduled commands.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScheduler

Returns a new instance of Scheduler.



11
12
13
14
# File 'lib/cron_kubernetes/scheduler.rb', line 11

def initialize
  @schedule   = []
  @identifier = CronKubernetes.identifier
end

Instance Attribute Details

#scheduleObject (readonly)

Returns the value of attribute schedule.



9
10
11
# File 'lib/cron_kubernetes/scheduler.rb', line 9

def schedule
  @schedule
end

Instance Method Details

#command(command, schedule:, name: nil) ⇒ Object



29
30
31
# File 'lib/cron_kubernetes/scheduler.rb', line 29

def command(command, schedule:, name: nil)
  @schedule << new_cron_job(schedule, command, name)
end

#rake(task, schedule:, name: nil) ⇒ Object



16
17
18
19
20
# File 'lib/cron_kubernetes/scheduler.rb', line 16

def rake(task, schedule:, name: nil)
  rake_command = "bundle exec rake #{task} --silent"
  rake_command = "RAILS_ENV=#{rails_env} #{rake_command}" if rails_env
  @schedule << new_cron_job(schedule, rake_command, name)
end

#runner(ruby_command, schedule:, name: nil) ⇒ Object



22
23
24
25
26
27
# File 'lib/cron_kubernetes/scheduler.rb', line 22

def runner(ruby_command, schedule:, name: nil)
  env = nil
  env = "-e #{rails_env} " if rails_env
  runner_command = "bin/rails runner #{env}'#{ruby_command}'"
  @schedule << new_cron_job(schedule, runner_command, name)
end