Module: Lita::Standups::Mixins::Robot

Included in:
Robot
Defined in:
lib/lita/standups/mixins/robot.rb

Instance Method Summary collapse

Instance Method Details

#initialize(*args) ⇒ Object



5
6
7
8
# File 'lib/lita/standups/mixins/robot.rb', line 5

def initialize(*args)
  @scheduler = Rufus::Scheduler.new if scheduler_enabled?
  super
end

#jobs_infoObject

:nocov:



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/lita/standups/mixins/robot.rb', line 69

def jobs_info
  scheduler.jobs.map do |job|
    [
      "Type: #{job.class}",
      "ID: #{job.job_id}",
      "Tags: #{job.tags.join(', ')}",
      ("Options: #{job.opts.except(:tags).inspect}" if job.opts.except(:tags).size > 0),
      "Next Run: #{job.next_time} (#{job.next_time - Time.now} seconds from now)",
      "Schedule: #{job.try(:original)}"
    ].compact
  end
end

#runObject



82
83
84
85
# File 'lib/lita/standups/mixins/robot.rb', line 82

def run
  schedule_standups
  super
end

#run_standup(standup_id, recipients, room_id) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/lita/standups/mixins/robot.rb', line 55

def run_standup(standup_id, recipients, room_id)
  if scheduler_enabled?
    scheduler.in "5s", tags: [:standup_schedules, :run_standup] do |job|
      Ohm.redis = Redic.new(Ohm.redis.url)
      Lita.logger.debug "Calling run on Manager for standup #{standup_id} (recipients: #{recipients.join(", ")}"
      Lita::Standups::Manager.run(robot: self, standup_id: standup_id, recipients: recipients, room: room_id)
    end
  else
    Lita.logger.debug "Calling run on Manager for standup #{standup_id} (recipients: #{recipients.join(", ")}"
    Lita::Standups::Manager.run(robot: self, standup_id: standup_id, recipients: recipients, room: room_id)
  end
end

#schedule_standup(standup_schedule) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/lita/standups/mixins/robot.rb', line 39

def schedule_standup(standup_schedule)
  return unless scheduler_enabled?
  scheduler.cron standup_schedule.cron_line, schedule_id: standup_schedule.id,
    tags: [:standup_schedules, "standup_schedule_#{standup_schedule.id}"] do |job|
      Ohm.redis = Redic.new(Ohm.redis.url)
      Lita.logger.debug "Calling run_schedule on Manager for #{job.opts[:schedule_id]}"
      Lita::Standups::Manager.run_schedule(robot: self, schedule_id: job.opts[:schedule_id])
  end
end

#schedule_standupsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lita/standups/mixins/robot.rb', line 20

def schedule_standups
  return unless scheduler_enabled?
  Lita.logger.debug "Unscheduling any existing jobs"
  scheduler.jobs.each(&:unschedule)
  Lita.logger.debug "Scheduling standup status jobs"
  scheduler.cron '*/15 * * * * *', tags: [:standup_schedules, :abort_expired] do |job|
    Ohm.redis = Redic.new(Ohm.redis.url)
    Lita::Standups::Manager.abort_expired_standups(robot: self)
  end
  scheduler.cron '*/15 * * * * *', tags: [:standup_schedules, :complete_finished] do |job|
    Ohm.redis = Redic.new(Ohm.redis.url)
    Lita::Standups::Manager.complete_finished_standups(robot: self)
  end
  Lita.logger.debug "Scheduling standups"
  Models::StandupSchedule.all.each do |standup_schedule|
    schedule_standup(standup_schedule)
  end
end

#schedulerObject

:nocov:



11
12
13
# File 'lib/lita/standups/mixins/robot.rb', line 11

def scheduler
  @scheduler
end

#scheduler_enabled?Boolean

:nocov:

Returns:

  • (Boolean)


16
17
18
# File 'lib/lita/standups/mixins/robot.rb', line 16

def scheduler_enabled?
  ENV['TEST'].nil?
end

#unschedule_standup(standup_schedule) ⇒ Object



49
50
51
52
53
# File 'lib/lita/standups/mixins/robot.rb', line 49

def unschedule_standup(standup_schedule)
  return unless scheduler_enabled?
  Lita.logger.debug "Unscheduling standup scheduled #{standup_schedule.id}"
  scheduler.jobs(tags: [:standup_schedules, "standup_schedule_#{standup_schedule.id}"]).each(&:unschedule)
end