Class: Stackify::MsgsQueue

Inherits:
SizedQueue
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/stackify/msgs_queue.rb

Constant Summary collapse

CHUNK_MIN_WEIGHT =
50
ERROR_SIZE =
10
LOG_SIZE =
1
DELAY_WAITING =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMsgsQueue

Returns a new instance of MsgsQueue.



12
13
14
15
# File 'lib/stackify/msgs_queue.rb', line 12

def initialize
  super(Stackify.configuration.queue_max_size)
  start_worker
end

Instance Attribute Details

#workerObject

Returns the value of attribute worker.



5
6
7
# File 'lib/stackify/msgs_queue.rb', line 5

def worker
  @worker
end

Instance Method Details

#add_msg(msg) ⇒ Object Also known as: <<, push



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/stackify/msgs_queue.rb', line 43

def add_msg msg
  Stackify.internal_log :debug, "[MsgsQueue] add_msg() Is worker <#{@worker.name}> alive? = #{@worker.alive?}"
  if !@worker.alive?
    start_worker
    Stackify.internal_log :debug, "[MsgsQueue] add_msg() Newly created worker <#{@worker.name}>"
  end
  self.synchronize do
    case Stackify.configuration.transport
    when Stackify::DEFAULT
      Stackify::Utils.do_only_if_authorized_and_mode_is_on Stackify::MODES[:logging] do
        old_push(msg)
      end
    when Stackify::UNIX_SOCKET, Stackify::AGENT_HTTP
      old_push(msg)
    end
  end
end

#push_remained_msgsObject



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/stackify/msgs_queue.rb', line 30

def push_remained_msgs
  Stackify.internal_log :debug, "[MsgsQueue] push_remained_msgs() alive? = #{@worker.alive?}"
  wait_until_all_workers_will_add_msgs
  self.synchronize do
    Stackify.internal_log :info, '[MsgsQueue] All remained logs are going to be sent'
    Stackify.shutdown_all
    if self.length > 0
      Stackify.get_transport.send_logs(pop_all)
      Stackify.status = Stackify::STATUSES[:terminated]
    end
  end
end

#start_workerObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/stackify/msgs_queue.rb', line 19

def start_worker
  if Stackify::Utils.is_mode_on? Stackify::MODES[:logging]
    @send_interval = ScheduleDelay.new
    @worker = MsgsQueueWorker.new
    task = update_send_interval_task
    @worker.async_perform @send_interval, task
  else
    Stackify.internal_log :warn, '[MsgsQueue]: Logging is disabled at configuration!'
  end
end