reportsmash 0.3.4 → 0.3.5

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: 14cd7c12034124af77849b8ef7f55d9e4c2c0a32
4
- data.tar.gz: 9c23277da9ba56adb66dc8f67586d755513e335d
3
+ metadata.gz: b1bdce2079cc27dd030216c1bf9a0ab336573d8e
4
+ data.tar.gz: 37667eb9450942119dfcdd3c90aeff97e800cdd2
5
5
  SHA512:
6
- metadata.gz: ed2b2e9d3db5f0714c3ae8e84009b7a0c187be67c13fa460a8db01877e0737e59aa2eb323cb4e999b50cc1ed11b968f0913b9b7d51bea91552a44e7ec88e349b
7
- data.tar.gz: c51189ec9cf46989d58fd925f82903ec6e183649b0d9e53d579e28d35119b24625176583f9debe8f048715cf0b563bad59b4b01d45593d2b33d565d03320fc79
6
+ metadata.gz: cee6a4972d2c3f64e571fda4e24d057d98d1e58510176800cb1d23094d4846978056edf2e57a0e10a6399d31aee012a2e2e23ad04ab8d9a72c18df1e0f56b1d1
7
+ data.tar.gz: 1faaf595786390e617b8046eee987c622fb2f64e8a30f174bb201a8c04bf5681347815eec8c8a201a03d91cb806226525a42e4749a08185e1c1084dcedc75a6f
@@ -1,4 +1,5 @@
1
1
  require 'thread'
2
+ require 'typhoeus'
2
3
  require 'snappy'
3
4
 
4
5
  module ReportsMash
@@ -0,0 +1,57 @@
1
+ require 'thread'
2
+ require 'typhoeus'
3
+ require 'snappy'
4
+
5
+ module ReportsMash
6
+ module Engine
7
+
8
+ # A worker loop executes a set of registered tasks on a single thread.
9
+ # A task is a proc or block with a specified call period in seconds.
10
+ class WorkerLoop
11
+
12
+ def initialize
13
+ @engine = ReportsMash::Engine.engine
14
+ end
15
+ def run
16
+ #$stderr.puts "ReportsMash worker running #{@engine}\n"
17
+ authkey = Base64.strict_encode64("#{ENV['REPORTSMASH_APP_ID']}:#{ENV['REPORTSMASH_APP_KEY']}")
18
+ if Rails.env.development?
19
+ remote_host = "https://in.reportsmash.com:8091/w"
20
+ else
21
+ remote_host = "https://in.reportsmash.com:443/w"
22
+ end
23
+ data = {}
24
+ batch = []
25
+
26
+ loop do
27
+ sleep 5
28
+ while item = @engine.delivery_queue.pop do
29
+ batch << item.payload
30
+ end
31
+ next if batch.count == 0
32
+ data[:transactions] = batch
33
+
34
+ begin
35
+ json_data = data.to_json
36
+ compressed_data = Snappy.deflate(json_data)
37
+
38
+ req = Typhoeus::Request.new(remote_host, method: :post, body: compressed_data, headers: {
39
+ "X-REPORTSMASH-AUTH" => authkey,
40
+ "Content-Length" => compressed_data.size,
41
+ "Content-Type" => "application/octet-stream" })
42
+ req.run
43
+ rescue Exception => e
44
+ $stderr.puts "ReportsMash::Engine.worker - could not send data to servers: #{e.inspect}"
45
+ end
46
+ #data[:transactions].each do |item|
47
+ # $stderr.puts "Batch running #{item}" if Rails.env.development?
48
+ #end
49
+
50
+ data.clear()
51
+ batch.clear()
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
@@ -1,3 +1,3 @@
1
1
  module ReportsMash
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module ReportsMash
2
- VERSION = "0.3.3"
2
+ VERSION = "0.3.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reportsmash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zeljko Tomic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-09 00:00:00.000000000 Z
11
+ date: 2016-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -80,6 +80,7 @@ files:
80
80
  - lib/reportsmash/engine/threading.rb
81
81
  - lib/reportsmash/engine/transaction.rb
82
82
  - lib/reportsmash/engine/worker.rb
83
+ - lib/reportsmash/engine/worker.rb~
83
84
  - lib/reportsmash/rack.rb
84
85
  - lib/reportsmash/rack/hooks.rb
85
86
  - lib/reportsmash/version.rb