Module: Botany::Scheduling

Included in:
Bot
Defined in:
lib/botany/scheduling.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.schedule_whenever!(config) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/botany/scheduling.rb', line 25

def self.schedule_whenever! config
  config.job_type :run_bot, 'cd :path && bundle exec botany run :task :output'

  Botany::Bot.each do |bot|
    bot.whenever_configuration_entries.each do |entry|
      config.instance_exec &entry
    end
  end
end

.update_cron!Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/botany/scheduling.rb', line 35

def self.update_cron!
  options = {
    string: 'Botany::Scheduling.schedule_whenever! self',
    update: true,
    identifier: Bundler.root,
    file: __FILE__ # We just need any file to prevent whenever from exiting
  }

  Signal.trap 'EXIT' do
    Whenever::CommandLine.execute options
  end
end

Instance Method Details

#schedule(&block) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/botany/scheduling.rb', line 5

def schedule &block
  if block_given?
    instance_eval &block
  else
    schedule_entries
  end
end

#whenever_configuration_entriesObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/botany/scheduling.rb', line 13

def whenever_configuration_entries
  schedule_entries.map do |entry|
    task = "#{name}.perform"

    lambda do
      every *entry do
        run_bot task
      end
    end
  end
end