Class: Lita::Standups::Manager
- Inherits:
-
Object
- Object
- Lita::Standups::Manager
- Defined in:
- lib/lita/standups/manager.rb
Constant Summary collapse
- DEFAULT_EXPIRATION_TIME =
3600
Instance Attribute Summary collapse
-
#robot ⇒ Object
Returns the value of attribute robot.
-
#session ⇒ Object
Returns the value of attribute session.
Class Method Summary collapse
- .abort_expired_standups(robot:) ⇒ Object
- .complete_finished_standups(robot:) ⇒ Object
- .run(robot:, standup_id:, recipients:, room:) ⇒ Object
- .run_schedule(robot:, schedule_id:) ⇒ Object
Instance Method Summary collapse
- #ask_questions(recipient) ⇒ Object
-
#initialize(robot:, session:) ⇒ Manager
constructor
A new instance of Manager.
- #post_results ⇒ Object
- #room ⇒ Object
- #run ⇒ Object
- #standup ⇒ Object
Constructor Details
#initialize(robot:, session:) ⇒ Manager
Returns a new instance of Manager.
60 61 62 63 |
# File 'lib/lita/standups/manager.rb', line 60 def initialize(robot:, session:) @robot = robot @session = session end |
Instance Attribute Details
#robot ⇒ Object
Returns the value of attribute robot.
58 59 60 |
# File 'lib/lita/standups/manager.rb', line 58 def robot @robot end |
#session ⇒ Object
Returns the value of attribute session.
58 59 60 |
# File 'lib/lita/standups/manager.rb', line 58 def session @session end |
Class Method Details
.abort_expired_standups(robot:) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lita/standups/manager.rb', line 37 def self.abort_expired_standups(robot:) Lita.logger.debug "Checking for expired standups" Lita::Standups::Models::StandupResponse.find(status: "pending").union(status: "running").each do |response| next unless Time.current - response.created_at > DEFAULT_EXPIRATION_TIME Lita.logger.debug "Found expired standup response: #{response.inspect}. Expiring ..." response.expired! response.save Lita::Wizard.cancel_wizard(response.user.id) target = Lita::Source.new(user: response.user, room: nil, private_message: true) robot. target, "Expired. See you next time!" end end |
.complete_finished_standups(robot:) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/lita/standups/manager.rb', line 50 def self.complete_finished_standups(robot:) Lita.logger.debug "Checking for finished sesssions" Lita::Standups::Models::StandupSession.find(status: "completed", results_sent: "0").each do |session| Lita.logger.debug "Found finished session: #{session.inspect}. Posting results ..." new(robot: robot, session: session).post_results end end |
.run(robot:, standup_id:, recipients:, room:) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/lita/standups/manager.rb', line 9 def self.run(robot:, standup_id:, recipients:, room:) session = Models::StandupSession.create( standup_id: standup_id, recipients: recipients, room: room ) new(robot: robot, session: session).run end |
.run_schedule(robot:, schedule_id:) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lita/standups/manager.rb', line 18 def self.run_schedule(robot:, schedule_id:) Lita.logger.debug "Running scheduled standup for schedule ID=#{schedule_id}" schedule = Models::StandupSchedule[schedule_id] Lita.logger.debug "Found scheduled standup: #{schedule.inspect}" session = Lita::Standups::Models::StandupSession.create( standup: schedule.standup, standup_schedule: schedule, recipients: schedule.recipients, room: schedule.channel ) Lita.logger.debug "Created session: #{session.inspect}" new(robot: robot, session: session).run rescue Exception => e Lita.logger.debug "Got exception while trying to run schedule ID #{schedule_id}" Lita.logger.debug e.inspect Lita.logger.debug e.backtrace.join("\n") raise e end |
Instance Method Details
#ask_questions(recipient) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/lita/standups/manager.rb', line 80 def ask_questions(recipient) user = Lita::User.fuzzy_find(recipient) Lita.logger.debug "Running the wizard for recipient #{recipient} (#{user.inspect})" response = Models::StandupResponse.create( standup_session_id: session.id, user_id: user.id ) dummy_source = Lita::Source.new(user: user, room: nil, private_message: true) = Lita::Message.new(robot, '', dummy_source) begin Wizards::RunStandup.start robot, , 'response_id' => response.id rescue Exception => e Lita.logger.debug "Got exception while trying to run the standup with #{recipient}" Lita.logger.debug e.inspect Lita.logger.debug e.backtrace.join("\n") response.aborted! response.save end end |
#post_results ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/lita/standups/manager.rb', line 100 def post_results return if session.results_sent == "1" = "The standup '#{standup.name}' has finished. Here's what everyone posted:\n\n#{session.}" robot. room, session.results_sent = "1" session.save end |
#room ⇒ Object
69 70 71 |
# File 'lib/lita/standups/manager.rb', line 69 def room @room ||= Lita::Source.new(user: nil, room: session.room) end |
#run ⇒ Object
73 74 75 76 77 78 |
# File 'lib/lita/standups/manager.rb', line 73 def run Lita.logger.debug "Running standup for session ID=#{session.id}" session.running! session.save session.recipients.each { |recipient| ask_questions(recipient) } end |
#standup ⇒ Object
65 66 67 |
# File 'lib/lita/standups/manager.rb', line 65 def standup session.standup end |