Class: Qbot::Cron

Inherits:
Base
  • Object
show all
Defined in:
lib/qbot/embed/cron.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#cache, #call, cron, #initialize, on, #post

Constructor Details

This class inherits a constructor from Qbot::Base

Class Method Details

.timersObject



24
25
26
# File 'lib/qbot/embed/cron.rb', line 24

def self.timers
  @timers ||= {}
end

Instance Method Details

#list_allObject



44
45
46
47
48
49
50
51
52
# File 'lib/qbot/embed/cron.rb', line 44

def list_all
  resp = StringIO.new
  cache.each do |id, (cron, text)|
    next unless cron && text
    resp.puts dump_line(id, cron, text)
  end

  resp.string
end

#start(id, cron, text) ⇒ Object



28
29
30
31
32
33
# File 'lib/qbot/embed/cron.rb', line 28

def start(id, cron, text)
  schedule(id, cron, text) rescue return

  cache[id] = [cron, text]
  "ADD " + dump_line(id, cron, text)
end

#stop(id) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/qbot/embed/cron.rb', line 35

def stop(id)
  Cron.timers[id].cancel if Cron.timers[id]
  cron, text = cache[id]
  return unless cron && text

  cache[id]  = nil
  "DEL " + dump_line(id, cron, text)
end