Class: Hackle::PollingWorkspaceFetcher
- Inherits:
-
Object
- Object
- Hackle::PollingWorkspaceFetcher
- Defined in:
- lib/hackle/workspaces/polling_workspace_fetcher.rb
Constant Summary collapse
- DEFAULT_POLLING_INTERVAL =
10
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(config:, http_fetcher:) ⇒ PollingWorkspaceFetcher
constructor
A new instance of PollingWorkspaceFetcher.
- #poll ⇒ Object
- #start! ⇒ Object
- #stop! ⇒ Object
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
#fetch ⇒ Object
18 19 20 |
# File 'lib/hackle/workspaces/polling_workspace_fetcher.rb', line 18 def fetch @current_workspace.get end |
#poll ⇒ Object
37 38 39 40 41 42 |
# File 'lib/hackle/workspaces/polling_workspace_fetcher.rb', line 37 def poll workspace = @http_fetcher.fetch @current_workspace.set(workspace) rescue => e @logger.error { "Failed to poll Workspace: #{e.inspect}" } end |
#start! ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/hackle/workspaces/polling_workspace_fetcher.rb', line 22 def start! return if @running poll @task.execute @running = true end |
#stop! ⇒ Object
30 31 32 33 34 35 |
# File 'lib/hackle/workspaces/polling_workspace_fetcher.rb', line 30 def stop! return unless @running @task.shutdown @running = false end |