Class: MailRunner::ManagerBot

Inherits:
Object
  • Object
show all
Extended by:
BotHelpers
Defined in:
lib/mail_runner/head_manager_bot.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeManagerBot

Returns a new instance of ManagerBot.



24
25
26
27
28
29
# File 'lib/mail_runner/head_manager_bot.rb', line 24

def initialize
  @mailbox = nil
  @webhook = nil
  @archive = false
  @webhook_status = nil
end

Instance Attribute Details

#archiveObject

Returns the value of attribute archive.



19
20
21
# File 'lib/mail_runner/head_manager_bot.rb', line 19

def archive
  @archive
end

#mailboxObject

used for testing



17
18
19
# File 'lib/mail_runner/head_manager_bot.rb', line 17

def mailbox
  @mailbox
end

#webhookObject

Returns the value of attribute webhook.



18
19
20
# File 'lib/mail_runner/head_manager_bot.rb', line 18

def webhook
  @webhook
end

#webhook_statusObject

Returns the value of attribute webhook_status.



20
21
22
# File 'lib/mail_runner/head_manager_bot.rb', line 20

def webhook_status
  @webhook_status
end

Instance Method Details

#delayed_queue?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/mail_runner/head_manager_bot.rb', line 89

def delayed_queue?
  queue_manager.queue_length > 0
end

#delegate_delayed_queue_processingObject



93
94
95
96
97
98
99
# File 'lib/mail_runner/head_manager_bot.rb', line 93

def delegate_delayed_queue_processing
  begin
    queue_manager.process_queue
  rescue Exception => msg 
    puts msg.inspect
  end
end

#delegate_inbound_processingObject



76
77
78
79
80
81
82
# File 'lib/mail_runner/head_manager_bot.rb', line 76

def delegate_inbound_processing
  begin
    inbound_manager.process_inbound(mailbox, webhook, archive)
  rescue Exception => msg 
    puts msg.inspect
  end
end

#inbound_managerObject



72
73
74
# File 'lib/mail_runner/head_manager_bot.rb', line 72

def inbound_manager
  MailRunner::InboundManagerBot
end

#parse_options(opts) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/mail_runner/head_manager_bot.rb', line 37

def parse_options(opts)
  BotHelpers::Tests.all_args_included?(opts)
  
  @mailbox = "/var/mail/#{opts[:mailbox]}"
  @webhook = opts[:webhook]
  @archive = opts[:archive] == "true" ? true : false 
end

#queue_managerObject



85
86
87
# File 'lib/mail_runner/head_manager_bot.rb', line 85

def queue_manager
  MailRunner::QueueManagerBot
end

#runObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/mail_runner/head_manager_bot.rb', line 54

def run
  BotHelpers::Helpers.print_monitoring_started_msg(self)
  $mad_statter.incr_stat("runner launched")
  while true 

    delegate_inbound_processing
    
    if webhook_status == "down"
      BotHelpers::Tests.soft_test_webhook(self.webhook)
    elsif delayed_queue?
      delegate_delayed_queue_processing
    end

    sleep 5
  end
end

#test_optionsObject



49
50
51
52
# File 'lib/mail_runner/head_manager_bot.rb', line 49

def test_options
  BotHelpers::Tests.test_mailbox(self.mailbox)
  BotHelpers::Tests.test_webhook(self.webhook)
end

#update_webhook_status(status) ⇒ Object



45
46
47
# File 'lib/mail_runner/head_manager_bot.rb', line 45

def update_webhook_status(status)
  @webhook_status = status
end

#verify_and_set(opts) ⇒ Object



32
33
34
35
# File 'lib/mail_runner/head_manager_bot.rb', line 32

def verify_and_set(opts)
  parse_options(opts)
  test_options       
end