Class: Nucleus::Adapters::V1::CloudControl::Logs::LogPoller

Inherits:
Object
  • Object
show all
Defined in:
lib/nucleus/adapters/v1/cloud_control/log_poller.rb

Instance Method Summary collapse

Constructor Details

#initialize(adapter, headers_to_use) ⇒ LogPoller

Initialize a new instance

Parameters:



12
13
14
15
16
# File 'lib/nucleus/adapters/v1/cloud_control/log_poller.rb', line 12

def initialize(adapter, headers_to_use)
  @adapter = adapter
  @headers_to_use = headers_to_use
  @last_log_entry = {}
end

Instance Method Details

#start(application_name, logs_to_poll, stream) ⇒ void

This method returns an undefined value.

Start the continuous polling of the logs.

Parameters:

  • application_name (String)

    the name (the ID) of the application

  • logs_to_poll (Array<String>)

    IDs of the logs to poll

  • stream (StreamCallback)

    stream callback to push messages



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/nucleus/adapters/v1/cloud_control/log_poller.rb', line 23

def start(application_name, logs_to_poll, stream)
  @polling_active = true
  # 1 log: wait 4 seconds between polls
  # 4 logs: 1 seconds
  timeout = logs_to_poll.length == 1 ? 4 : 1
  logs_to_poll.each { |log_to_poll| @last_log_entry[log_to_poll] = nil }

  fetch_action = lambda do
    update_log(application_name, logs_to_poll, stream)
    # start next iteration if we are still supposed to be active
    EM.add_timer(timeout) { fetch_action.call } if @polling_active
  end
  # start the loop to poll the logs
  EM.add_timer(timeout) { fetch_action.call }
end

#stopObject

Stop the polling at the next shot



40
41
42
# File 'lib/nucleus/adapters/v1/cloud_control/log_poller.rb', line 40

def stop
  @polling_active = false
end