Class: StayAwake::Strategies::Httparty
- Inherits:
-
Object
- Object
- StayAwake::Strategies::Httparty
- Includes:
- Singleton, StayAwake::Strategy
- Defined in:
- lib/stay_awake/strategies/httparty.rb
Class Method Summary collapse
Methods included from StayAwake::Strategy
Class Method Details
.available? ⇒ Boolean
6 7 8 |
# File 'lib/stay_awake/strategies/httparty.rb', line 6 def self.available? defined?(HTTParty) ? true : false end |
.buzz(url) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/stay_awake/strategies/httparty.rb', line 10 def self.buzz(url) require 'timeout' StayAwake.logger.info 'Starting buzzing using HTTParty.' @thread = Thread.new do loop do begin Timeout.timeout(30) do uuid = SecureRandom.uuid StayAwake.logger.debug "Starting HTTP Request (#{uuid})." HTTParty.send(StayAwake.config.request_method, url) StayAwake.logger.debug "HTTP Response arrived (#{uuid})." # TODO: Failing request? end rescue Timeout::Error StayAwake.logger.error "HTTP Timeout Error after 30 seconds (#{uuid})." rescue StandardError => e StayAwake.logger.error e. end sleep StayAwake.config.interval end end end |
.shut_off ⇒ Object
35 36 37 38 39 |
# File 'lib/stay_awake/strategies/httparty.rb', line 35 def self.shut_off @thread.kill @thread = nil StayAwake.logger.info 'Stopped buzzing.' end |