lib/stackify/logs_sender.rb in stackify-api-ruby-1.0.2 vs lib/stackify/logs_sender.rb in stackify-api-ruby-1.0.3

- old
+ new

@@ -1,60 +1,30 @@ module Stackify class LogsSender < HttpClient LOGS_URI = URI("#{Stackify.configuration.base_api_url}/Log/Save") - def start - worker = Stackify::Worker.new 'Main sending thread' - task = Stackify::ScheduleTask.new do - send_logs - end - worker.async_perform Stackify.configuration.send_interval, task - Stackify.internal_log :debug, 'LogsSender: main sending thread is started' - end - - def send_remained_msgs - if Stackify.working? - Stackify.internal_log :warn, 'Sending of remained msgs is possible when Stackify is terminating work.' - else - worker = Stackify::Worker.new 'RemainedJob worker' - task = send_all_remained_msgs_task Stackify.msgs_queue.pop_all - worker.perform 2, task - end - end - - private - - def send_logs attempts = 3 - msgs = Stackify.msgs_queue.pop #it should wait until queue will get a new chunk if queque is empty + def send_logs msgs, attempts = 3 worker = Stackify::LogsSenderWorker.new task = send_logs_task attempts, msgs - worker.async_perform 5, task + worker.async_perform ScheduleDelay.new, task end + private + def properties { - success_condition: lambda { |result| result.try(:code) == '200' }, + success_condition: lambda { |result| result.try(:status) == 200 }, limit: 1 }.dup end def send_logs_task attempts = nil, msgs properties[:attempts] = attempts if attempts Stackify::ScheduleTask.new properties do failure_msg = 'LogsSender: tried to send logs' Stackify.if_not_authorized failure_msg do Stackify.internal_log :info, 'LogsSender: trying to send logs to Stackify...' - send_request LOGS_URI, gather_and_pack_data(msgs).to_json - end - end - end - - def send_all_remained_msgs_task msgs - Stackify::ScheduleTask.new properties do - failure_msg = 'LogsSender: tried to remained send logs' - Stackify.if_not_authorized failure_msg do - Stackify.internal_log :info, 'LogsSender: trying to send remained logs to Stackify...' send_request LOGS_URI, gather_and_pack_data(msgs).to_json end end end