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.



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

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

Instance Attribute Details

#archiveObject

Returns the value of attribute archive.



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

def archive
  @archive
end

#mailboxObject

used for testing



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

def mailbox
  @mailbox
end

#webhookObject

Returns the value of attribute webhook.



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

def webhook
  @webhook
end

#webhook_statusObject

Returns the value of attribute webhook_status.



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

def webhook_status
  @webhook_status
end

Instance Method Details

#archive_stack?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/mail_runner/head_manager_bot.rb', line 112

def archive_stack?
  archivist.stack_height > 0
end

#archivistObject



108
109
110
# File 'lib/mail_runner/head_manager_bot.rb', line 108

def archivist
  MailRunner::ArchivistBot
end

#delayed_queue?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/mail_runner/head_manager_bot.rb', line 96

def delayed_queue?
	queue_manager.queue_length > 0
end

#delegate_archive_stack_processingObject



116
117
118
119
120
121
122
# File 'lib/mail_runner/head_manager_bot.rb', line 116

def delegate_archive_stack_processing
  begin
    archivist.archive_stack
  rescue Exception => msg 
    puts msg.inspect
  end
end

#delegate_delayed_queue_processingObject



100
101
102
103
104
105
106
# File 'lib/mail_runner/head_manager_bot.rb', line 100

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

#delegate_inbound_processingObject



83
84
85
86
87
88
89
# File 'lib/mail_runner/head_manager_bot.rb', line 83

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

#inbound_managerObject

Delegation Methods ####



79
80
81
# File 'lib/mail_runner/head_manager_bot.rb', line 79

def inbound_manager
	MailRunner::InboundManagerBot
end

#parse_options(opts) ⇒ Object



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

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

#queue_managerObject



92
93
94
# File 'lib/mail_runner/head_manager_bot.rb', line 92

def queue_manager
	MailRunner::QueueManagerBot
end

#runObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mail_runner/head_manager_bot.rb', line 56

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

    if archive_stack?
      delegate_archive_stack_processing
    end

		sleep 5
	end
end

#test_optionsObject



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

def test_options
  BotHelpers::Tests.test_mailbox(self.mailbox)
  BotHelpers::Tests.test_webhook(self.webhook)
  BotHelpers::Tests.test_archive(self.archive) unless self.archive.nil?
end

#update_webhook_status(status) ⇒ Object



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

def update_webhook_status(status)
	@webhook_status = status
end

#verify_and_set(opts) ⇒ Object



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

def verify_and_set(opts)
  parse_options(opts)
  test_options       
end