stackify-api-ruby 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e279fd82f66b4a337b740251468dc61f5f9bb8d
4
- data.tar.gz: 0a03ef09c48705211493eabd72ebfdfc17f34a2c
3
+ metadata.gz: 91576c0ba41af7311a30a4fad37f1d79d6094183
4
+ data.tar.gz: cf5c824bb9ab986fcb497bc9ed1ed754a4f3093d
5
5
  SHA512:
6
- metadata.gz: 0ca663b56f8a19bdcacdd896280387095c63e9d621bffe98b573b58851a5092be74cd305541568185c9cbf8be26cb7e7347c7f675b6a9bf241d1e9f1c58cef6a
7
- data.tar.gz: 56c4de85f2e95928019973e5210c00be97f05882b3c0c45668e6855e00c63265cf002b937c05cb538b06049addf5b3f4a4e773d3904bc10911c62866761e097a
6
+ metadata.gz: 2b76008856dec9a3222956299826567e8c5f410c814034620bd4288f8e90104803b166163b83fd1aba30c7ba24596a558691b30017d5e61b16f6b320aa198038
7
+ data.tar.gz: 4f5ec661d4004383633a6fe4807435cc447e697a81e54bc29603ac3566ba318effa84eb8a38e0b4db449675a945bbdb366dd28070bb0bf2e91be9f83371c1011
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ stackify-api-ruby
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.2
data/Gemfile.lock CHANGED
@@ -1,11 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stackify-api-ruby (1.0.2)
4
+ stackify-api-ruby (1.0.3)
5
+ faraday (>= 0.8)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
10
+ faraday (0.9.0)
11
+ multipart-post (>= 1.2, < 3)
12
+ multipart-post (2.0.0)
9
13
  rake (0.9.6)
10
14
 
11
15
  PLATFORMS
data/README.md CHANGED
@@ -62,11 +62,7 @@ You can set minimal level of logs, which should be caught by gem:
62
62
 
63
63
  If you want to use proxy for sending request, you can do it in such way:
64
64
 
65
- config.with_proxy = true
66
- config.proxy_host = "127.0.0.1"
67
- config.proxy_port = "8118"
68
- config.proxy_user = nil
69
- config.proxy_pass = nil
65
+ config.proxy = { uri: '127.0.0.1:8118', user: 'user_name', password: 'some_password' }
70
66
 
71
67
  For internal logging stackify-api-ruby uses such logger:
72
68
 
@@ -6,9 +6,5 @@ Stackify.setup do |config|
6
6
  #config.log_level = :error
7
7
  #config.logger = Logger.new(File.join(Rails.root, 'log', 'stackify.log'))
8
8
  #config.logger.level = Logger::INFO
9
- #config.with_proxy = false
10
- #config.proxy_host = '127.0.0.1'
11
- #config.proxy_port = '8118'
12
- #config.proxy_user = nil
13
- #config.proxy_pass = nil
9
+ #config.proxy = {uri: '127.0.0.1:8118', user: 'user_name', password: 'some_password'}
14
10
  end
@@ -16,9 +16,11 @@ module Stackify
16
16
  autoload :EnvDetails, 'stackify/env_details'
17
17
  autoload :Scheduler, 'stackify/scheduler'
18
18
  autoload :ScheduleTask, 'stackify/schedule_task'
19
+ autoload :ScheduleDelay, 'stackify/schedule_delay'
19
20
  autoload :Worker, 'stackify/workers/worker'
20
21
  autoload :AuthWorker, 'stackify/workers/auth_worker'
21
22
  autoload :LogsSenderWorker, 'stackify/workers/logs_sender_worker'
23
+ autoload :MsgsQueueWorker, 'stackify/workers/msgs_queue_worker'
22
24
  autoload :AddMsgWorker, 'stackify/workers/add_msg_worker'
23
25
  autoload :MsgsQueue, 'stackify/msgs_queue'
24
26
  autoload :LoggerClient, 'stackify/logger_client'
@@ -123,7 +125,7 @@ module Stackify
123
125
  end
124
126
 
125
127
  def start_logging
126
- Thread.new { Stackify.logs_sender.start}
128
+ msgs_queue
127
129
  end
128
130
 
129
131
  def start_metrics
@@ -10,11 +10,11 @@ module Stackify::Authorizable
10
10
  @@auth_lock = Mutex.new
11
11
  @@auth_client = nil
12
12
 
13
- def authorize attempts=3, delay_time = 20
13
+ def authorize attempts=3
14
14
  @@auth_lock.synchronize do
15
15
  return unless @@auth_client.nil?
16
16
  @@auth_client = Stackify::Authorizable::AuthorizationClient.new
17
- @@auth_client.auth attempts, delay_time
17
+ @@auth_client.auth attempts
18
18
  end
19
19
  end
20
20
 
@@ -53,7 +53,7 @@ module Stackify::Authorizable
53
53
 
54
54
  def response_string r
55
55
  return '' if r.nil?
56
- "Code: #{r.try(:code)}, Message: '#{r.try(:msg)}'"
56
+ "Status: #{r.try(:status)}, Message: '#{r.try(:body)}'"
57
57
  end
58
58
 
59
59
  end
@@ -8,7 +8,7 @@ module Stackify::Authorizable
8
8
  @worker = Stackify::AuthWorker.new
9
9
  end
10
10
 
11
- def auth attempts, delay_time= 20
11
+ def auth attempts, delay_time= Stackify::ScheduleDelay.new
12
12
  task = auth_task attempts
13
13
  @worker.perform delay_time, task
14
14
  end
@@ -18,7 +18,7 @@ module Stackify::Authorizable
18
18
  limit: 1,
19
19
  attempts: attempts,
20
20
  success_condition: lambda do |result|
21
- result.try(:code) == '200'
21
+ result.try(:status) == 200
22
22
  end
23
23
  }
24
24
  Stackify::ScheduleTask.new properties do
@@ -1,6 +1,7 @@
1
+ require 'digest'
2
+
1
3
  module Stackify
2
4
  class ErrorsGovernor
3
- require 'digest'
4
5
 
5
6
  def initialize purge_period=5
6
7
  @history = {}
@@ -17,7 +18,7 @@ module Stackify
17
18
  history_entry = @history[key]
18
19
  if history_entry[:epoch_minute] == epoch_minute
19
20
  history_entry[:count] += 1
20
- answer = (history_entry[:count] <= Stackify.configuration.flood_limit) ? true : false
21
+ answer = history_entry[:count] <= Stackify.configuration.flood_limit
21
22
  else
22
23
  @history[key]={
23
24
  epoch_minute: epoch_minute,
@@ -1,6 +1,6 @@
1
1
  require 'uri'
2
- require 'net/http'
3
- require 'net/https'
2
+ require 'faraday'
3
+
4
4
  module Stackify
5
5
  class HttpClient
6
6
 
@@ -16,32 +16,21 @@ module Stackify
16
16
  def send_request uri, body, headers = HEADERS
17
17
  @errors = []
18
18
  begin
19
- https = get_https uri
20
- req = Net::HTTP::Post.new uri.path, initheader = headers
21
- req.body = body
19
+ conn = Faraday.new(proxy: Stackify.configuration.proxy)
22
20
  Stackify.internal_log :debug, "============Request body=========================="
23
- Stackify.internal_log :debug, req.body
21
+ Stackify.internal_log :debug, body
24
22
  Stackify.internal_log :debug, "=================================================="
25
- @response = https.request req
26
- rescue => ex
23
+ @response = conn.post do |req|
24
+ req.url URI(uri)
25
+ req.headers = headers
26
+ req.body = body
27
+ end
28
+ rescue => ex
27
29
  @errors << ex
28
30
  Stackify.log_internal_error('HttpClient: ' + ex.message+ ' Backtrace: '+ Stackify::Backtrace.backtrace_in_line(ex.backtrace))
29
31
  false
30
32
  end
31
33
  end
32
34
 
33
- def get_https uri
34
- if Stackify.configuration.with_proxy
35
- https = Net::HTTP.new uri.host, uri.port,
36
- Stackify.configuration.proxy_host,
37
- Stackify.configuration.proxy_port,
38
- Stackify.configuration.proxy_user,
39
- Stackify.configuration.proxy_pass
40
- else
41
- https = Net::HTTP.new uri.host, uri.port
42
- end
43
- https.use_ssl = true
44
- https
45
- end
46
35
  end
47
36
  end
@@ -1,6 +1,5 @@
1
1
  module Stackify
2
2
  class LoggerClient
3
- PERIOD = 1
4
3
 
5
4
  def initialize
6
5
  @@errors_governor = Stackify::ErrorsGovernor.new
@@ -11,7 +10,7 @@ module Stackify
11
10
  if acceptable? level, msg && Stackify.working?
12
11
  worker = Stackify::AddMsgWorker.new
13
12
  task = log_message_task level, msg
14
- worker.async_perform PERIOD, task
13
+ worker.async_perform ScheduleDelay.new, task
15
14
  end
16
15
  end
17
16
  end
@@ -23,7 +22,7 @@ module Stackify
23
22
  if @@errors_governor.can_send? ex
24
23
  worker = Stackify::AddMsgWorker.new
25
24
  task = log_exception_task level, ex
26
- worker.async_perform PERIOD, task
25
+ worker.async_perform ScheduleDelay.new, task
27
26
  else
28
27
  Stackify.internal_log :warn,
29
28
  "LoggerClient: logging of exception with message \"#{ex.message}\" is skipped - flood_limit is exceeded"
@@ -59,17 +58,13 @@ module Stackify
59
58
 
60
59
  def log_message_task level, msg
61
60
  Stackify::ScheduleTask.new ({limit: 1}) do
62
- Stackify.msgs_queue.add_msg Stackify::MsgObject.new(level, msg, caller[0]).to_h
63
- str = "LoggerClient: logging of message #{msg} with level '#{level}' is completed successfully."
64
- Stackify.internal_log :debug, str
61
+ Stackify.msgs_queue << Stackify::MsgObject.new(level, msg, caller[0]).to_h
65
62
  end
66
63
  end
67
64
 
68
65
  def log_exception_task level, ex
69
66
  Stackify::ScheduleTask.new ({limit: 1}) do
70
- Stackify.msgs_queue.add_msg Stackify::MsgObject.new(level, ex.message, caller[0], ex).to_h
71
- Stackify.internal_log :debug, 'LoggerClient: '+
72
- 'Logging of the exception %p: %s is completed successfully' % [ ex.class, ex.message ]
67
+ Stackify.msgs_queue << Stackify::MsgObject.new(level, ex.message, caller[0], ex).to_h
73
68
  end
74
69
  end
75
70
  end
@@ -3,37 +3,17 @@ module Stackify
3
3
 
4
4
  LOGS_URI = URI("#{Stackify.configuration.base_api_url}/Log/Save")
5
5
 
6
- def start
7
- worker = Stackify::Worker.new 'Main sending thread'
8
- task = Stackify::ScheduleTask.new do
9
- send_logs
10
- end
11
- worker.async_perform Stackify.configuration.send_interval, task
12
- Stackify.internal_log :debug, 'LogsSender: main sending thread is started'
13
- end
14
-
15
- def send_remained_msgs
16
- if Stackify.working?
17
- Stackify.internal_log :warn, 'Sending of remained msgs is possible when Stackify is terminating work.'
18
- else
19
- worker = Stackify::Worker.new 'RemainedJob worker'
20
- task = send_all_remained_msgs_task Stackify.msgs_queue.pop_all
21
- worker.perform 2, task
22
- end
23
- end
24
-
25
- private
26
-
27
- def send_logs attempts = 3
28
- msgs = Stackify.msgs_queue.pop #it should wait until queue will get a new chunk if queque is empty
6
+ def send_logs msgs, attempts = 3
29
7
  worker = Stackify::LogsSenderWorker.new
30
8
  task = send_logs_task attempts, msgs
31
- worker.async_perform 5, task
9
+ worker.async_perform ScheduleDelay.new, task
32
10
  end
33
11
 
12
+ private
13
+
34
14
  def properties
35
15
  {
36
- success_condition: lambda { |result| result.try(:code) == '200' },
16
+ success_condition: lambda { |result| result.try(:status) == 200 },
37
17
  limit: 1
38
18
  }.dup
39
19
  end
@@ -49,16 +29,6 @@ module Stackify
49
29
  end
50
30
  end
51
31
 
52
- def send_all_remained_msgs_task msgs
53
- Stackify::ScheduleTask.new properties do
54
- failure_msg = 'LogsSender: tried to remained send logs'
55
- Stackify.if_not_authorized failure_msg do
56
- Stackify.internal_log :info, 'LogsSender: trying to send remained logs to Stackify...'
57
- send_request LOGS_URI, gather_and_pack_data(msgs).to_json
58
- end
59
- end
60
- end
61
-
62
32
  def gather_and_pack_data msgs
63
33
  details = Stackify::EnvDetails.instance.auth_info
64
34
  {
@@ -17,7 +17,7 @@ module Stackify::Metrics
17
17
  worker = Stackify::Worker.new 'Metrics client - processing of metrics'
18
18
  Stackify.internal_log :debug, 'Metrics client: processing of metrics is started'
19
19
  task = submit_metrics_task
20
- worker.async_perform 5, task
20
+ worker.async_perform Stackify::ScheduleDelay.new, task
21
21
  else
22
22
  Stackify.internal_log :warn, '[MetricClient]: Processing of metrics is disabled at configuration!'
23
23
  end
@@ -51,11 +51,10 @@ module Stackify::Metrics
51
51
  Stackify.internal_log :warn, '[MetricClient]: Adding of metrics is impossible - Stackify is terminating or terminated work.'
52
52
  end
53
53
  end
54
-
54
+
55
55
  private
56
-
56
+
57
57
  def start_upload_metrics
58
- all_is_ok = false
59
58
  current_time = Stackify::Utils.rounded_current_time
60
59
  purge_older_than = current_time - 10.minutes
61
60
  #read everything up to the start of the current minute
@@ -140,7 +139,7 @@ module Stackify::Metrics
140
139
  end
141
140
 
142
141
  def submit_metrics_task
143
- Stackify::ScheduleTask.new do
142
+ Stackify::ScheduleTask.new do
144
143
  start_upload_metrics
145
144
  end
146
145
  end
@@ -9,18 +9,17 @@ module Stackify::Metrics
9
9
  alias :old_push :push
10
10
 
11
11
  def add_metric metric
12
- self.synchronize do
12
+ self.synchronize do
13
13
  self.old_push metric
14
14
  end
15
15
  end
16
16
 
17
- alias :old_size :size
17
+ alias :old_size :size
18
18
 
19
- def size
20
- self.synchronize do
19
+ def size
20
+ self.synchronize do
21
21
  self.old_size
22
22
  end
23
23
  end
24
-
25
24
  end
26
- end
25
+ end
@@ -1,15 +1,22 @@
1
1
  module Stackify
2
2
  class MsgsQueue < SizedQueue
3
3
  include MonitorMixin
4
- #TODO: restrict possibility to work with class if app is off
4
+
5
5
  CHUNK_MIN_WEIGHT = 50
6
6
  ERROR_SIZE = 10
7
7
  LOG_SIZE = 1
8
- DELAY_WAITING = 2
8
+ DELAY_WAITING = 1
9
9
 
10
10
  def initialize
11
11
  super(Stackify.configuration.queue_max_size)
12
- reset_current_chunk
12
+ if Stackify::Utils.is_mode_on? Stackify::MODES[:logging]
13
+ @send_interval = ScheduleDelay.new
14
+ worker = MsgsQueueWorker.new
15
+ task = update_send_interval_task
16
+ worker.async_perform @send_interval, task
17
+ else
18
+ Stackify.internal_log :warn, '[MsgsQueue]: Logging is disabled at configuration!'
19
+ end
13
20
  end
14
21
 
15
22
  alias :old_push :push
@@ -17,11 +24,10 @@ module Stackify
17
24
  def push_remained_msgs
18
25
  wait_until_all_workers_will_add_msgs
19
26
  self.synchronize do
20
- push_current_chunk
27
+ Stackify.internal_log :info, 'All remained logs are going to be sent'
21
28
  Stackify.shutdown_all
22
29
  if self.length > 0
23
- Stackify.logs_sender.send_remained_msgs
24
- Stackify.internal_log :info, 'All remained logs are sent'
30
+ Stackify.logs_sender.send_logs(pop_all)
25
31
  Stackify.status = Stackify::STATUSES[:terminated]
26
32
  end
27
33
  end
@@ -29,14 +35,8 @@ module Stackify
29
35
 
30
36
  def add_msg msg
31
37
  self.synchronize do
32
- if msg.is_a?(Hash)
33
- @current_chunk_weight += msg['Ex'].nil? ? LOG_SIZE : ERROR_SIZE
34
- @current_chunk << msg
35
- if @current_chunk_weight >= CHUNK_MIN_WEIGHT
36
- push_current_chunk
37
- end
38
- else
39
- Stackify.log_internal_error "MsgsQueue: add_msg should get hash, but not a #{msg.class}"
38
+ Stackify::Utils.do_only_if_authorized_and_mode_is_on Stackify::MODES[:logging] do
39
+ old_push(msg)
40
40
  end
41
41
  end
42
42
  end
@@ -44,6 +44,8 @@ module Stackify
44
44
  alias :<< :add_msg
45
45
  alias :push :add_msg
46
46
 
47
+ private
48
+
47
49
  def pop_all
48
50
  self.synchronize do
49
51
  msgs = []
@@ -54,23 +56,57 @@ module Stackify
54
56
  end
55
57
  end
56
58
 
57
- private
58
-
59
- def reset_current_chunk
60
- @current_chunk = []
61
- @current_chunk_weight = 0
62
- end
63
-
64
59
  def wait_until_all_workers_will_add_msgs
60
+ @send_interval = 120
65
61
  while Stackify.alive_adding_msg_workers.size > 0
62
+ @send_interval += DELAY_WAITING
66
63
  sleep DELAY_WAITING
67
64
  end
68
65
  end
69
66
 
70
- def push_current_chunk
71
- unless @current_chunk.empty?
72
- self.old_push(@current_chunk)
73
- reset_current_chunk
67
+ def update_send_interval_task
68
+ properties = {
69
+ success_condition: lambda do |result|
70
+ true
71
+ end
72
+ }
73
+ Stackify::ScheduleTask.new properties do
74
+ processed_count = calculate_processed_msgs_count
75
+ i = @send_interval.update_by_sent_num! processed_count
76
+ Stackify.internal_log :debug, "MsgsQueue: send_interval is updated to #{i}"
77
+ i
78
+ end
79
+ end
80
+
81
+ def calculate_processed_msgs_count
82
+ processed_count = 0
83
+ keep_going = true
84
+ begin
85
+ count = push_one_chunk
86
+ keep_going = count >= 50
87
+ processed_count += count
88
+ end while keep_going
89
+ processed_count
90
+ end
91
+
92
+ def push_one_chunk
93
+ chunk_weight = 0
94
+ chunk = []
95
+ started_at = Time.now.to_f * 1000
96
+ self.synchronize do
97
+ while(true)
98
+ if length > 0
99
+ msg = pop
100
+ chunk << msg
101
+ chunk_weight += (msg['Ex'].nil? ? LOG_SIZE : ERROR_SIZE)
102
+ break if msg['EpochMs'] > started_at || CHUNK_MIN_WEIGHT > 50
103
+ else
104
+ break
105
+ end
106
+ end
107
+
108
+ Stackify.logs_sender.send_logs(chunk) if chunk.length > 0
109
+ chunk_weight
74
110
  end
75
111
  end
76
112
  end
@@ -0,0 +1,45 @@
1
+ module Stackify
2
+ class ScheduleDelay
3
+
4
+ ONE_SECOND = 1.0
5
+ ONE_MINUTE = 60.0
6
+ FIVE_SECONDS = 5.0
7
+ FIVE_MINUTES = 300.0
8
+
9
+ def initialize (delay = ONE_SECOND)
10
+ @delay = delay
11
+ @last_http_error_occured_time = 0
12
+ end
13
+
14
+ def update_by_sent_num! num_sent
15
+ @last_http_error_occured_time = 0
16
+ if num_sent >= 100
17
+ @delay = [(@delay/ 2.0).round(2), ONE_SECOND].max
18
+ elsif num_sent < 10
19
+ @delay = [(@delay * 1.25).round(2), FIVE_SECONDS].min
20
+ end
21
+ end
22
+
23
+ def update_by_exeption! e
24
+ if is_authorized_exeption?(e)
25
+ @last_http_error_occured_time = Time.now if @last_http_error_occured_time == 0
26
+ since_first_error = (Time.now - @last_http_error_occured_time).round(2)
27
+ @delay = [[since_first_error, ONE_SECOND].max, ONE_MINUTE].min
28
+ else
29
+ @last_http_error_occured_time = Time.now
30
+ @delay = FIVE_MINUTES
31
+ end
32
+ end
33
+
34
+ def to_sec
35
+ @delay
36
+ end
37
+
38
+ private
39
+
40
+ def is_authorized_exeption? ex
41
+ ex.try(:status) == 401
42
+ end
43
+ end
44
+
45
+ end
@@ -9,7 +9,7 @@ module Stackify
9
9
  def initialize
10
10
  @should_run = true
11
11
  @next_invocation_time = Time.now
12
- @period = 60.0
12
+ @period = ScheduleDelay.new
13
13
  @iterations = 0
14
14
  @attempts = 3
15
15
  end
@@ -21,7 +21,7 @@ module Stackify
21
21
  @iterations = 0
22
22
  @attempts = @task.attempts if @task.attempts
23
23
  now = Time.now
24
- @next_invocation_time = (now + @period)
24
+ @next_invocation_time = (now + @period.to_sec)
25
25
  end
26
26
 
27
27
  def run(period=nil, task)
@@ -34,6 +34,7 @@ module Stackify
34
34
  @iterations += 1
35
35
  @attempts = @task.attempts || @attempts
36
36
  else
37
+ @period.update_by_exeption!(@task_result)
37
38
  @attempts -= 1
38
39
  end
39
40
  end
@@ -42,8 +43,8 @@ module Stackify
42
43
 
43
44
  def schedule_next_invocation
44
45
  now = Time.now
45
- while @next_invocation_time <= now && @period > 0
46
- @next_invocation_time += @period
46
+ while @next_invocation_time <= now && @period.to_sec > 0
47
+ @next_invocation_time += @period.to_sec
47
48
  end
48
49
  @next_invocation_time - Time.now
49
50
  end
@@ -2,8 +2,8 @@ module Stackify
2
2
 
3
3
  class Configuration
4
4
 
5
- attr_accessor :api_key, :app_name, :app_location, :env, :log_level, :logger, :with_proxy,
6
- :proxy_host, :proxy_port, :proxy_user, :proxy_pass, :mode, :base_api_url
5
+ attr_accessor :api_key, :app_name, :app_location, :env, :log_level, :logger,
6
+ :proxy, :mode, :base_api_url
7
7
 
8
8
  attr_reader :errors, :send_interval, :flood_limit, :queue_max_size
9
9
 
@@ -13,9 +13,8 @@ module Stackify
13
13
  @api_key = ''
14
14
  @env = :production
15
15
  @flood_limit = 100
16
- @queue_max_size = 1000
16
+ @queue_max_size = 10000
17
17
  @send_interval = 60
18
- @with_proxy = false
19
18
  @log_level = :info
20
19
  @mode = MODES[:both]
21
20
  @logger = if defined? Rails
@@ -1,3 +1,3 @@
1
1
  module Stackify
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
@@ -7,7 +7,7 @@ module Stackify
7
7
  end
8
8
 
9
9
  def after_perform result
10
- if result.try(:code) == '200'
10
+ if result.try(:status) == 200
11
11
  Stackify.send :authorized!
12
12
  Stackify.successfull_authorisation result
13
13
  else
@@ -7,7 +7,7 @@ module Stackify
7
7
  end
8
8
 
9
9
  def after_perform result
10
- if result.try(:code) == '200'
10
+ if result.try(:status) == 200
11
11
  Stackify.internal_log :info, "#{@name}: Sending batch of msgs is successfully completed"
12
12
  else
13
13
  Stackify.log_internal_error "#{@name}: Sending batch of msgs is failed: #{result.try(:msg)}"
@@ -0,0 +1,13 @@
1
+ module Stackify
2
+ class MsgsQueueWorker < Worker
3
+
4
+ def initialize name = 'MsgsQueue worker'
5
+ super
6
+ @type = :send_msgs
7
+ Stackify.internal_log :info, "#{@name}: started sending logs"
8
+ end
9
+
10
+ def after_perform result
11
+ end
12
+ end
13
+ end
@@ -13,18 +13,18 @@ module Stackify
13
13
  Stackify.add_dependant_worker self
14
14
  end
15
15
 
16
- def async_perform period=1.0, task
16
+ def async_perform period=ScheduleDelay.new, task
17
17
  run_scheduler task, period
18
18
  end
19
19
 
20
- def perform period=1.0, task
20
+ def perform period=ScheduleDelay.new, task
21
21
  run_scheduler task, period, true
22
22
  end
23
23
 
24
24
  def shutdown!
25
25
  Stackify.delete_worker self
26
26
  if @worker_thread
27
- Stackify.internal_log :info, "Thread with name \"#{@name}\" is terminated!"
27
+ Stackify.internal_log :debug, "Thread with name \"#{@name}\" is terminated!"
28
28
  Thread.kill @worker_thread
29
29
  else
30
30
  Stackify.internal_log :warn, "Thread with name \"#{@name}\" is terminated with exception!"
@@ -52,9 +52,9 @@ module Stackify
52
52
  'Untitled worker'
53
53
  end
54
54
 
55
- def run_scheduler task, period, sync = false
55
+ def run_scheduler task, delay, sync = false
56
56
  @worker_thread = Thread.new do
57
- @scheduler.run period, task
57
+ @scheduler.run delay, task
58
58
  after_perform @scheduler.task_result if respond_to? :after_perform
59
59
  shutdown!
60
60
  end
@@ -5,7 +5,7 @@ require 'stackify/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'stackify-api-ruby'
8
- spec.version = '1.0.2'
8
+ spec.version = '1.0.3'
9
9
  spec.authors = ['Stackify']
10
10
  spec.email = ['support@stackify.com']
11
11
  spec.summary = 'Stackify API for Ruby'
@@ -20,5 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.6'
22
22
  spec.add_development_dependency 'rake', '~> 0'
23
-
23
+ spec.add_runtime_dependency 'faraday', '>= 0.8'
24
24
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stackify-api-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stackify
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-27 00:00:00.000000000 Z
11
+ date: 2014-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
41
55
  description: Stackify Logs and Metrics API for Ruby
42
56
  email:
43
57
  - support@stackify.com
@@ -45,6 +59,8 @@ executables: []
45
59
  extensions: []
46
60
  extra_rdoc_files: []
47
61
  files:
62
+ - ".ruby-gemset"
63
+ - ".ruby-version"
48
64
  - Gemfile
49
65
  - Gemfile.lock
50
66
  - README.md
@@ -74,6 +90,7 @@ files:
74
90
  - lib/stackify/metrics/monitor.rb
75
91
  - lib/stackify/msgs_queue.rb
76
92
  - lib/stackify/rack/errors_catcher.rb
93
+ - lib/stackify/schedule_delay.rb
77
94
  - lib/stackify/schedule_task.rb
78
95
  - lib/stackify/scheduler.rb
79
96
  - lib/stackify/utils/backtrace.rb
@@ -84,6 +101,7 @@ files:
84
101
  - lib/stackify/workers/add_msg_worker.rb
85
102
  - lib/stackify/workers/auth_worker.rb
86
103
  - lib/stackify/workers/logs_sender_worker.rb
104
+ - lib/stackify/workers/msgs_queue_worker.rb
87
105
  - lib/stackify/workers/worker.rb
88
106
  - spec/spec_helper.rb
89
107
  - stackify-api-ruby.gemspec