Class: Stackify::MsgsQueue
- 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
-
#worker ⇒ Object
Returns the value of attribute worker.
Instance Method Summary collapse
- #add_msg(msg) ⇒ Object (also: #<<, #push)
-
#initialize ⇒ MsgsQueue
constructor
A new instance of MsgsQueue.
- #push_remained_msgs ⇒ Object
- #start_worker ⇒ Object
Constructor Details
#initialize ⇒ MsgsQueue
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
#worker ⇒ Object
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. Stackify::MODES[:logging] do old_push(msg) end when Stackify::UNIX_SOCKET, Stackify::AGENT_HTTP old_push(msg) end end end |
#push_remained_msgs ⇒ Object
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_worker ⇒ Object
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 |