class Hackle::PollingWorkspaceFetcher

Constants

DEFAULT_POLLING_INTERVAL

Public Class Methods

new(config:, http_fetcher:) click to toggle source
# File lib/hackle/workspaces/polling_workspace_fetcher.rb, line 10
def initialize(config:, http_fetcher:)
  @logger = config.logger
  @http_fetcher = http_fetcher
  @current_workspace = Concurrent::AtomicReference.new
  @task = Concurrent::TimerTask.new(execution_interval: DEFAULT_POLLING_INTERVAL) { poll }
  @running = false
end

Public Instance Methods

fetch() click to toggle source

@return [Workspace, nil]

# File lib/hackle/workspaces/polling_workspace_fetcher.rb, line 19
def fetch
  @current_workspace.get
end
poll() click to toggle source
# File lib/hackle/workspaces/polling_workspace_fetcher.rb, line 40
def poll
  workspace = @http_fetcher.fetch
  @current_workspace.set(workspace)
rescue => e
  @logger.error { "Failed to poll Workspace: #{e.inspect}" }
end
start!() click to toggle source
# File lib/hackle/workspaces/polling_workspace_fetcher.rb, line 23
def start!
  return if @running

  poll
  @task.execute
  @running = true
end
stop!() click to toggle source
# File lib/hackle/workspaces/polling_workspace_fetcher.rb, line 31
def stop!
  return unless @running

  @logger.info { 'Shutting down Hackle workspace_fetcher' }

  @task.shutdown
  @running = false
end