Class: StatusChecker::Check
- Inherits:
-
Object
- Object
- StatusChecker::Check
- Defined in:
- lib/status_checker/check.rb
Instance Method Summary collapse
- #check_url(url) ⇒ Object
-
#initialize(email = ["[email protected]"], per = 10, domain = ["https://ukr.net", "https://yandex.ru"]) ⇒ Check
constructor
A new instance of Check.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(email = ["[email protected]"], per = 10, domain = ["https://ukr.net", "https://yandex.ru"]) ⇒ Check
Returns a new instance of Check.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/status_checker/check.rb', line 9 def initialize(email=["[email protected]"], per=10, domain=["https://ukr.net", "https://yandex.ru"]) # initialize all instanse variables extend MonitorMixin @email = email @delay = per @domain = domain @timer = StatusChecker::Timer.new(@delay) @resp_stack = Hash.new end |
Instance Method Details
#check_url(url) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/status_checker/check.rb', line 38 def check_url(url) response = check_http_status_of(url) if response.code != 200.to_s && !recurrent_code?(url, response.code) add_code_to_resp_stack(response.code, url) send_email(url, response) end [url, response.code, response.] end |
#start ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/status_checker/check.rb', line 20 def start # run checker loop threads = [] @timer.start do @domain.each do |dom| threads << Thread.new(dom) do |url| check_url(url) end end threads.each { |thr| thr.join } end end |
#stop ⇒ Object
33 34 35 36 |
# File 'lib/status_checker/check.rb', line 33 def stop # stop checker loop @timer.stop end |