Class: Cosmo::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/cosmo/processor.rb

Overview

rubocop:disable Metrics/ClassLength

Direct Known Subclasses

Job::Processor, Stream::Processor

Constant Summary collapse

STREAM_PAUSED_RECHECK_TTL =

Seconds a stream’s paused state is cached before re-checking (override via COSMO_STREAM_PAUSED_RECHECK_TTL)

5.0
STREAMS_PAUSED_IDLE_SLEEP =

Seconds to sleep when every stream is paused, preventing a tight CPU spin (override via COSMO_STREAMS_PAUSED_IDLE_SLEEP)

1.0
STREAM_EMPTY_BACKOFF_MAX =

Max seconds to sleep between empty fetches (override via COSMO_STREAM_EMPTY_BACKOFF_MAX)

5.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pool, running, options) ⇒ Processor

Returns a new instance of Processor.



15
16
17
18
19
20
21
22
# File 'lib/cosmo/processor.rb', line 15

def initialize(pool, running, options)
  @pool = pool
  @running = running
  @options = options
  @threads = []
  @consumers = []
  @cache = Utils::TTLCache.new
end

Instance Attribute Details

#consumersObject (readonly)

Returns the value of attribute consumers.



13
14
15
# File 'lib/cosmo/processor.rb', line 13

def consumers
  @consumers
end

Class Method Details

.runObject



9
10
11
# File 'lib/cosmo/processor.rb', line 9

def self.run(...)
  new(...).tap(&:run)
end

Instance Method Details

#runObject



24
25
26
27
28
29
30
# File 'lib/cosmo/processor.rb', line 24

def run
  setup
  return unless @consumers.any?

  @running.make_true
  run_loop
end

#stop(timeout = ) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/cosmo/processor.rb', line 32

def stop(timeout = Config[:timeout])
  @running.make_false
  @pool.shutdown
  @consumers.each { |(s, _)| s.unsubscribe rescue nil }
  @pool.wait_for_termination(timeout)
  @threads.compact.each { _1.join(timeout) || _1.kill }
  @consumers.clear
  @threads.clear
end