Class: Hackle::PollingWorkspaceFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/hackle/workspaces/polling_workspace_fetcher.rb

Constant Summary collapse

DEFAULT_POLLING_INTERVAL =
10

Instance Method Summary collapse

Constructor Details

#initialize(config:, http_fetcher:) ⇒ PollingWorkspaceFetcher

Returns a new instance of PollingWorkspaceFetcher.



10
11
12
13
14
15
16
# 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

Instance Method Details

#fetchWorkspace?

Returns:



19
20
21
# File 'lib/hackle/workspaces/polling_workspace_fetcher.rb', line 19

def fetch
  @current_workspace.get
end

#pollObject



40
41
42
43
44
45
# 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!Object



23
24
25
26
27
28
29
# File 'lib/hackle/workspaces/polling_workspace_fetcher.rb', line 23

def start!
  return if @running

  poll
  @task.execute
  @running = true
end

#stop!Object



31
32
33
34
35
36
37
38
# 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