class Turnstile::Collector::Actor

Attributes

options[RW]
queue[RW]
sleep_when_idle[RW]
stopping[RW]
thread[RW]
tracker[RW]

Public Class Methods

actor_name(value = nil) click to toggle source
# File lib/turnstile/collector/actor.rb, line 14
def actor_name(value = nil)
  @actor_name = value if value
  @actor_name
end
new(queue:, tracker: nil, sleep_when_idle: Turnstile.config.flush_interval, **opts) click to toggle source
# File lib/turnstile/collector/actor.rb, line 27
def initialize(queue:,
               tracker: nil,
               sleep_when_idle: Turnstile.config.flush_interval,
               **opts)

  self.queue           = queue
  self.sleep_when_idle = sleep_when_idle
  self.tracker         = tracker || Turnstile::Tracker.new
  self.options         = opts
  self.stopping        = false

  Kernel.tdb "actor initialized: #{self.to_s}" if Turnstile.config.trace
end

Public Instance Methods

config() click to toggle source
# File lib/turnstile/collector/actor.rb, line 45
def config
  @config ||= Turnstile.config
end
create_thread(*args) { |*args| ... } click to toggle source
# File lib/turnstile/collector/actor.rb, line 73
def create_thread(*args, &_block)
  Thread.new(self.class.actor_name, *args) do |actor_name, *args|
    Thread.current[:name] = actor_name
    yield(*args) if block_given?
  end
end
execute() click to toggle source

Return nil when there is nothing else to do Return ideally a number representing number of remaining items.

# File lib/turnstile/collector/actor.rb, line 69
def execute
  raise ArgumentError, 'Abstract Method'
end
shutdown() click to toggle source
# File lib/turnstile/collector/actor.rb, line 41
def shutdown
  self.stopping = true
end
start() click to toggle source
# File lib/turnstile/collector/actor.rb, line 53
def start
  self.thread = create_thread(self, sleep_when_idle) do |actor, sleep_period|
    loop do
      items_remaining = actor.execute
      break if actor.stopping?
      sleep(sleep_period) unless items_remaining && items_remaining > 0
    end
  end
end
stopping?() click to toggle source
# File lib/turnstile/collector/actor.rb, line 49
def stopping?
  self.stopping
end
to_s() click to toggle source
# File lib/turnstile/collector/actor.rb, line 63
def to_s
  "<turnsile-actor##{self.class.name.gsub(/.*::/, '').downcase}: queue size: #{queue.size}, idle=#{sleep_when_idle}"
end