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 Method Summary collapse

Constructor Details

#initializeMsgsQueue

Returns a new instance of MsgsQueue.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/stackify/msgs_queue.rb', line 10

def initialize
  super(Stackify.configuration.queue_max_size)
  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

Instance Method Details

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



36
37
38
39
40
41
42
# File 'lib/stackify/msgs_queue.rb', line 36

def add_msg msg
  self.synchronize do
    Stackify::Utils.do_only_if_authorized_and_mode_is_on Stackify::MODES[:logging] do
      old_push(msg)
    end
  end
end

#push_remained_msgsObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/stackify/msgs_queue.rb', line 24

def push_remained_msgs
  wait_until_all_workers_will_add_msgs
  self.synchronize do
    Stackify.internal_log :info, 'All remained logs are going to be sent'
    Stackify.shutdown_all
    if self.length > 0
      Stackify.logs_sender.send_logs(pop_all)
      Stackify.status = Stackify::STATUSES[:terminated]
    end
  end
end