Class: Atatus::Transport::Worker Private

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/atatus/transport/worker.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: FlushMessage, StopMessage

Constant Summary

Constants included from Logging

Logging::LEVELS, Logging::PREFIX

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #error, #fatal, #info, #warn

Constructor Details

#initialize(config, queue, serializers:, filters:) ⇒ Worker

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Worker.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/atatus/transport/worker.rb', line 40

def initialize(
  config,
  queue,
  serializers:,
  filters:
)
  @config = config
  @queue = queue

  @serializers = serializers
  @filters = filters

  @connection = self.class.adapter.new(config)
end

Class Attribute Details

.adapterObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
# File 'lib/atatus/transport/worker.rb', line 27

def adapter
  @adapter ||= Connection
end

Instance Attribute Details

#connectionObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
# File 'lib/atatus/transport/worker.rb', line 55

def connection
  @connection
end

#filtersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
# File 'lib/atatus/transport/worker.rb', line 55

def filters
  @filters
end

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
# File 'lib/atatus/transport/worker.rb', line 55

def name
  @name
end

#queueObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
# File 'lib/atatus/transport/worker.rb', line 55

def queue
  @queue
end

#serializersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
# File 'lib/atatus/transport/worker.rb', line 55

def serializers
  @serializers
end

Instance Method Details

#process(resource) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



73
74
75
76
# File 'lib/atatus/transport/worker.rb', line 73

def process(resource)
  return unless (json = serialize_and_filter(resource))
  connection.write(json)
end

#work_foreverObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/atatus/transport/worker.rb', line 57

def work_forever
  while (msg = queue.pop)
    case msg
    when StopMessage
      debug 'Stopping worker [%s]', self
      connection.flush(:halt)
      break
    else
      process msg
    end
  end
rescue Exception => e
  warn 'Worker died with exception: %s', e.inspect
  debug e.backtrace.join("\n")
end