whenauser 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,14 +22,15 @@ In your Gemfile:
22
22
  You should create two incoming channels (event streams) in WhenAUser, and configure their tokens in `config/whenauser.rb` (the available options are explained below). You may want to create additional channels to use in other environments, eg for staging.
23
23
 
24
24
  token 'CHANNEL_TOKEN' # default channel (for user-centric events)
25
- middleware :pageviews # automatically generate events for pageviews
25
+ middleware :pageviews # automatically generate events for requests/pageviews
26
26
  middleware :exceptions do # automatically generate events for exceptions
27
27
  token 'ERROR_CHANNEL_TOKEN' # separate channel for error-centric events
28
28
  end
29
29
 
30
- ###As general-purpose Rack middleware, without Rails
30
+ ###As general-purpose Rack middleware, with or without Rails
31
31
 
32
- config.middleware.use 'WhenAUser::Rack', :token => 'CHANNEL_TOKEN_'
32
+ config.middleware.insert 0, 'WhenAUser::Rack', :token => 'CHANNEL_TOKEN'
33
+ config.middleware.insert_after 'WhenAUser::Rack', 'WhenAUser::Pageviews'
33
34
  config.middleware.use 'WhenAUser::Exceptions', :token => 'ERROR_CHANNEL_TOKEN'
34
35
 
35
36
  Using girl_friday for asynchronous communication and persistence
@@ -39,15 +40,20 @@ By default this gem sends a batch of events to the WhenAUser service synchronous
39
40
 
40
41
  queue WhenAUser::GirlFridayQueue
41
42
 
42
- You can also pass options to girl_friday. To avoid losing events when your app server instances restart, you can tell girl_friday to use Redis:
43
+ Using the GirlFridayQueue also ensures that events are not lost should the WhenAUser service be temporarily unavailable.
43
44
 
44
- queue WhenAUser::GirlFridayQueue,
45
- :store => GirlFriday::Store::Redis, :store_config => { :host => 'hostname', :port => 12345 }
45
+ You can also pass options to girl_friday. To avoid losing events when your app server instances restart, you can tell girl_friday to use Redis. In order to use the Redis backend, you must use the [connection_pool](https://github.com/mperham/connection_pool) gem to share a set of Redis connections with other threads and the GirlFriday queue. If you are not already using Redis in your application, add
46
+
47
+ gem 'connection_pool'
48
+ gem 'redis'
46
49
 
47
- If you already have a Redis connection pool, you can tell girl_friday to use it:
50
+ to your Gemfile, and add something like this to `config/whenauser.rb`:
48
51
 
52
+ require 'connection_pool'
53
+
54
+ redis_pool = ConnectionPool.new(:size => 5, :timeout => 5) { ::Redis.new }
49
55
  queue WhenAUser::GirlFridayQueue,
50
- :store => GirlFriday::Store::Redis, :store_config => { :pool => $redis }
56
+ :store => GirlFriday::Store::Redis, :store_config => { :pool => redis_pool }
51
57
 
52
58
  See the [girl_friday wiki](https://github.com/mperham/girl_friday/wiki) for more information on how to use girl_friday.
53
59
 
@@ -8,7 +8,17 @@ module WhenAUser
8
8
 
9
9
  def initialize
10
10
  super(:whenauser, {:size => 1}.merge(WhenAUser.queue_options)) do |msg|
11
- WhenAUser.post_payload_to_token msg[:payload], WhenAUser.token
11
+ retries = 0
12
+ begin
13
+ WhenAUser.post_payload_to_token msg[:payload], WhenAUser.token
14
+ rescue Exception => e
15
+ if (retries += 1) % 6 == 5
16
+ WhenAUser.logger.warn "WhenAUser having trouble sending events; #{retries} attempts so far."
17
+ end
18
+ sleep [5, retries].max
19
+ retry
20
+ end
21
+ WhenAUser.logger.warn "WhenAUser resuming service after #{retries} retries." unless retries == 0
12
22
  end
13
23
  end
14
24
 
@@ -1,3 +1,3 @@
1
1
  module WhenAUser
2
- VERSION = '0.4.4'
2
+ VERSION = '0.5.0'
3
3
  end
data/lib/whenauser.rb CHANGED
@@ -6,10 +6,11 @@ require 'whenauser/girl_friday_queue'
6
6
  require 'whenauser/memory_queue'
7
7
  require 'net/http'
8
8
  require 'uri'
9
+ require 'logger'
9
10
  require 'active_support/core_ext/module/attribute_accessors'
10
11
 
11
12
  module WhenAUser
12
- mattr_accessor :endpoint, :filter_parameters, :buffer, :token, :webhook_url, :queue, :queue_options
13
+ mattr_accessor :filter_parameters, :buffer, :token, :webhook_url, :queue, :queue_options, :logger
13
14
 
14
15
  def self.default_ignored_crawlers
15
16
  %w(Baidu Gigabot Googlebot libwww-perl lwp-trivial msnbot SiteUptime Slurp WordPress ZIBB ZyBorg Yandex Jyxobot Huaweisymantecspider ApptusBot)
@@ -45,6 +46,7 @@ module WhenAUser
45
46
  class Rack
46
47
  def initialize(app, options={})
47
48
  @app = app
49
+ WhenAUser.logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
48
50
  WhenAUser.webhook_url = options[:webhook_url] || 'http://www.whenauser.com/events/'
49
51
  WhenAUser.buffer = []
50
52
  WhenAUser.filter_parameters = defined?(Rails) ? Rails.application.config.filter_parameters : []
metadata CHANGED
@@ -1,71 +1,72 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: whenauser
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 4
8
- - 4
9
- version: 0.4.4
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - David Anderson
13
9
  - Chris Weis
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2012-08-02 00:00:00 +02:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2012-08-02 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
22
16
  name: activesupport
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
31
23
  type: :runtime
32
- version_requirements: *id001
33
- - !ruby/object:Gem::Dependency
34
- name: actionpack
35
24
  prerelease: false
36
- requirement: &id002 !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- segments:
41
- - 0
42
- version: "0"
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: actionpack
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
43
39
  type: :runtime
44
- version_requirements: *id002
45
- - !ruby/object:Gem::Dependency
46
- name: girl_friday
47
40
  prerelease: false
48
- requirement: &id003 !ruby/object:Gem::Requirement
49
- requirements:
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: girl_friday
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
50
52
  - - ~>
51
- - !ruby/object:Gem::Version
52
- segments:
53
- - 0
54
- - 10
55
- - 0
53
+ - !ruby/object:Gem::Version
56
54
  version: 0.10.0
57
55
  type: :runtime
58
- version_requirements: *id003
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 0.10.0
59
63
  description: Rack middleware for connecting to WhenAUser
60
- email:
64
+ email:
61
65
  - david@alpinegizmo.com
62
66
  executables: []
63
-
64
67
  extensions: []
65
-
66
68
  extra_rdoc_files: []
67
-
68
- files:
69
+ files:
69
70
  - .gitignore
70
71
  - Gemfile
71
72
  - README.md
@@ -79,35 +80,28 @@ files:
79
80
  - lib/whenauser/railtie.rb
80
81
  - lib/whenauser/version.rb
81
82
  - whenauser.gemspec
82
- has_rdoc: true
83
83
  homepage: https://github.com/tractionlabs/whenauser
84
84
  licenses: []
85
-
86
85
  post_install_message:
87
86
  rdoc_options: []
88
-
89
- require_paths:
87
+ require_paths:
90
88
  - lib
91
- required_ruby_version: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - ">="
94
- - !ruby/object:Gem::Version
95
- segments:
96
- - 0
97
- version: "0"
98
- required_rubygems_version: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - ">="
101
- - !ruby/object:Gem::Version
102
- segments:
103
- - 0
104
- version: "0"
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
105
101
  requirements: []
106
-
107
102
  rubyforge_project:
108
- rubygems_version: 1.3.6
103
+ rubygems_version: 1.8.24
109
104
  signing_key:
110
105
  specification_version: 3
111
106
  summary: Rack middleware for connecting to WhenAUser
112
107
  test_files: []
113
-