wat_catcher 0.0.8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cc313703208b28f0ebeb5456be66d62f38ca9873
4
+ data.tar.gz: 79a0d4e383b5cdd7c7678f7721f3e87c13f4d0de
5
+ SHA512:
6
+ metadata.gz: c4799cbdf9b74f9823f950f1b0fd19cb0d50a2bc9daddd273c6b099be5dfb5a6797dbc7c989b65e326e4e255d9a96fcf0ae5aed0269240a6cce02c29178fcc0c
7
+ data.tar.gz: e6945f9a2e9a6c9687331cbc13d3a4eaa9585d2eea26085f48254ef0921d9914d2bbbb4cda3a8b8cb5a09443e8410c6a3f6c8ed9e81bd6c38e223e022832b26a
@@ -2,35 +2,37 @@ module WatCatcher
2
2
  class Middleware
3
3
  def initialize(app)
4
4
  @app = app
5
- @client = HTTPClient.new
6
- @backgrounder = ::WatCatcher::Backgrounder.new
7
5
  end
8
6
 
9
7
  def call(env)
10
8
  @app.call(env)
11
9
  rescue
12
10
  excpt = $!
13
- @backgrounder.queue do
14
- request = ::Rack::Request.new(env)
15
- params = request.params
16
- session = request.session.as_json
17
- page_url = request.url
11
+ request = env["action_controller.instance"].request
12
+ params = request.filtered_parameters
13
+ session = request.session.as_json
14
+ page_url = request.url
18
15
 
19
- # Build the clean url (hide the port if it is obvious)
20
- url = "#{request.scheme}://#{request.host}"
21
- url << ":#{request.port}" unless [80, 443].include?(request.port)
22
- url << request.fullpath
16
+ # Build the clean url (hide the port if it is obvious)
17
+ url = "#{request.scheme}://#{request.host}"
18
+ url << ":#{request.port}" unless [80, 443].include?(request.port)
19
+ url << request.fullpath
23
20
 
24
- @client.post("#{WatCatcher.configuration.host}/wats",
25
- "wat[page_url]" => page_url,
26
- "wat[request_params]" => params,
27
- "wat[session]" => session,
28
- "wat[backtrace][]" => excpt.backtrace.to_a,
29
- "wat[message]" => excpt.message,
30
- "wat[error_class]" => excpt.class.to_s
31
- )
32
- end
21
+ ::WatCatcher::SidekiqPoster.perform_async(
22
+ "#{WatCatcher.configuration.host}/wats",
23
+ {
24
+ wat: {
25
+ page_url: page_url,
26
+ request_params: params,
27
+ session: session,
28
+ backtrace: excpt.backtrace.to_a,
29
+ message: excpt.message,
30
+ error_class: excpt.class.to_s
31
+ }
32
+ })
33
33
  raise
34
34
  end
35
35
  end
36
+
37
+
36
38
  end
@@ -0,0 +1,24 @@
1
+ module WatCatcher
2
+ class SidekiqMiddleware
3
+ def call(worker, msg, queue)
4
+ begin
5
+ yield
6
+ rescue => excpt
7
+ raise if msg["class"] == WatCatcher::SidekiqPoster.to_s
8
+ SidekiqPoster.perform_async(
9
+ "#{WatCatcher.configuration.host}/wats",
10
+ {
11
+ wat: {
12
+ backtrace: excpt.backtrace.to_a,
13
+ message: excpt.message,
14
+ error_class: excpt.class.to_s,
15
+ sidekiq_msg: msg
16
+
17
+ }
18
+ })
19
+ raise
20
+ end
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,13 @@
1
+ require 'sidekiq'
2
+
3
+ module WatCatcher
4
+ class SidekiqPoster
5
+ include Sidekiq::Worker
6
+
7
+ def perform(url, params)
8
+ HTTPClient.post_content(url,
9
+ body: params["wat"].merge({"app_env" => ::Rails.env.to_s}).to_json,
10
+ header: {"Content-Type" => "application/json; charset=utf-8"})
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module WatCatcher
2
- VERSION = "0.0.8"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/wat_catcher.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  require "wat_catcher/version"
2
2
 
3
- require 'wat_catcher/backgrounder'
3
+ require 'wat_catcher/sidekiq_poster'
4
4
  require "wat_catcher/middleware"
5
5
  require "wat_catcher/wattle_helper"
6
+ require "wat_catcher/sidekiq_middleware"
7
+ require "wat_catcher/sidekiq_poster"
8
+
6
9
 
7
10
  require "wat_catcher/railtie" if defined?(Rails::Railtie)
8
11
  module WatCatcher
data/wat_catcher.gemspec CHANGED
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "guard-coffeescript"
25
25
  spec.add_development_dependency "rb-readline"
26
26
  spec.add_runtime_dependency 'coffee-rails'
27
+ spec.add_runtime_dependency 'sidekiq'
28
+ spec.add_runtime_dependency 'httpclient'
27
29
  end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wat_catcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Chris Constantine
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-28 00:00:00.000000000 Z
11
+ date: 2013-07-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,81 +27,99 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: jasmine
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: guard-coffeescript
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - '>='
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - '>='
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rb-readline
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - '>='
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - '>='
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: coffee-rails
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - '>='
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :runtime
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sidekiq
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: httpclient
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
108
123
  - !ruby/object:Gem::Version
109
124
  version: '0'
110
125
  description: Catch your wats
@@ -123,10 +138,11 @@ files:
123
138
  - README.md
124
139
  - Rakefile
125
140
  - lib/wat_catcher.rb
126
- - lib/wat_catcher/backgrounder.rb
127
141
  - lib/wat_catcher/engine.rb
128
142
  - lib/wat_catcher/middleware.rb
129
143
  - lib/wat_catcher/railtie.rb
144
+ - lib/wat_catcher/sidekiq_middleware.rb
145
+ - lib/wat_catcher/sidekiq_poster.rb
130
146
  - lib/wat_catcher/version.rb
131
147
  - lib/wat_catcher/wattle_helper.rb
132
148
  - spec/javascripts/support/jasmine.yml
@@ -136,27 +152,26 @@ files:
136
152
  homepage: ''
137
153
  licenses:
138
154
  - MIT
155
+ metadata: {}
139
156
  post_install_message:
140
157
  rdoc_options: []
141
158
  require_paths:
142
159
  - lib
143
160
  required_ruby_version: !ruby/object:Gem::Requirement
144
- none: false
145
161
  requirements:
146
- - - ! '>='
162
+ - - '>='
147
163
  - !ruby/object:Gem::Version
148
164
  version: '0'
149
165
  required_rubygems_version: !ruby/object:Gem::Requirement
150
- none: false
151
166
  requirements:
152
- - - ! '>='
167
+ - - '>='
153
168
  - !ruby/object:Gem::Version
154
169
  version: '0'
155
170
  requirements: []
156
171
  rubyforge_project:
157
- rubygems_version: 1.8.21
172
+ rubygems_version: 2.0.3
158
173
  signing_key:
159
- specification_version: 3
174
+ specification_version: 4
160
175
  summary: A gem for registering Wats from your rails app
161
176
  test_files:
162
177
  - spec/javascripts/support/jasmine.yml
@@ -1,34 +0,0 @@
1
- module WatCatcher
2
- class Backgrounder
3
- def initialize
4
- @queue = Queue.new
5
- background_thread
6
-
7
- at_exit do
8
- @queue << false
9
- background_thread.join()
10
- end
11
- end
12
-
13
-
14
- def queue &block
15
- p "queueing"
16
- @queue << block
17
- end
18
-
19
- def background_thread
20
- @thread ||= Thread.new do
21
- running = true
22
- while running || !@queue.empty?
23
- msg = @queue.pop
24
- if msg
25
- msg.call
26
- else
27
- running = false
28
- end
29
- end
30
- end
31
- end
32
-
33
- end
34
- end