global_error_handler 0.1.2 → 0.1.10
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 +4 -4
- data/README.md +2 -1
- data/config/recipes/global_error_handler.rb +19 -0
- data/lib/global_error_handler/redis.rb +45 -6
- data/lib/global_error_handler/redis_notification_subscriber.rb +1 -1
- data/lib/global_error_handler/version.rb +1 -1
- data/lib/tasks/global_error_handler.rake +8 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8e1d5697e1bfb783ebc6f2ea2ba9e90d476c148
|
4
|
+
data.tar.gz: 1d6f01e6a420998b71837234e4f36246866d4f9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 048a744a25f0bdc8c9b96a7d68358af9e9d0862d5cf70a1ded5c69a7dc823cedf9ab727ea9530a72aa904ab828fc1fe19eeef67ed82c6a85eb369f19db0ae696
|
7
|
+
data.tar.gz: 9d5a3260b8daac46772ced2e7f1ebf20101fa5d64134b288a76453189647ca1196ef7d96e42566e0c326654143df18925d1cdc51e3d8966f9530ca390bd16bbf
|
data/README.md
CHANGED
@@ -9,6 +9,7 @@ It adds Exceptions tab to Redis Web server in case to view, filter, delete or tr
|
|
9
9
|
- [Exceptions tab](#exceptions-tab)
|
10
10
|
- [Truncate / Delete](#truncatedelete-functionality)
|
11
11
|
- [RescueFrom](#rescue_from)
|
12
|
+
- [Subscribe to Redis notifications](#subscribe-to-redis-notifications)
|
12
13
|
- [Data structure](#data-structure)
|
13
14
|
- [Contributing](#contributing)
|
14
15
|
|
@@ -55,7 +56,7 @@ If `rescue_from` is used in your application, add following line at top of the m
|
|
55
56
|
GlobalErrorHandler::Handler.new(request.env, exception).process_exception!
|
56
57
|
```
|
57
58
|
|
58
|
-
### Subscribe to
|
59
|
+
### Subscribe to Redis notifications
|
59
60
|
Following command should run on your server in case to automatically clear filters on deleting keys from redis due to expiration.
|
60
61
|
Default expiration time is set to 4 weeks (`GlobalErrorHandler::Redis::REDIS_TTL`)
|
61
62
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
namespace :global_error_handler do
|
2
|
+
desc 'Subscribe to expiration'
|
3
|
+
task :subscribe do
|
4
|
+
run %Q{cd #{latest_release} && RAILS_ENV=#{rails_env} nohup rake global_error_handler:subscribe_to_expired >/dev/null 2>&1 & sleep 2}
|
5
|
+
end
|
6
|
+
|
7
|
+
desc 'Unsubscribe from expiration'
|
8
|
+
task :unsubscribe do
|
9
|
+
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} global_error_handler:unsubscribe_from_expired}
|
10
|
+
end
|
11
|
+
|
12
|
+
desc 'Update Subscription to expiration'
|
13
|
+
task :update_subscription do
|
14
|
+
unsubscribe
|
15
|
+
subscribe
|
16
|
+
end
|
17
|
+
after 'deploy:restart', 'global_error_handler:update_subscription'
|
18
|
+
end
|
19
|
+
|
@@ -9,6 +9,7 @@ class GlobalErrorHandler::Redis
|
|
9
9
|
|
10
10
|
class << self
|
11
11
|
def store(info_hash)
|
12
|
+
return if info_hash.blank?
|
12
13
|
redis_key = exception_key(next_id!)
|
13
14
|
redis.hmset redis_key, info_hash.merge(id: current_id).to_a.flatten
|
14
15
|
redis.rpush EXCEPTIONS_REDIS_KEY, redis_key
|
@@ -18,12 +19,14 @@ class GlobalErrorHandler::Redis
|
|
18
19
|
redis.expire redis_key, REDIS_TTL
|
19
20
|
end
|
20
21
|
|
22
|
+
def initialize_redis_from_config #:nodoc:
|
23
|
+
redis_config = YAML.load_file(File.join(Rails.root, 'config', 'redis.yml'))[Rails.env]
|
24
|
+
Redis.new(redis_config['global_exception_handler'])
|
25
|
+
end
|
26
|
+
|
21
27
|
def redis
|
22
28
|
@redis ||= begin
|
23
|
-
unless $redis_global_exception_handler.is_a? Redis
|
24
|
-
redis_config = YAML.load_file(File.join(Rails.root, 'config', 'redis.yml'))[Rails.env]
|
25
|
-
$redis_global_exception_handler = Redis.new(redis_config['global_exception_handler'])
|
26
|
-
end
|
29
|
+
$redis_global_exception_handler = initialize_redis_from_config unless $redis_global_exception_handler.is_a? Redis
|
27
30
|
$redis_global_exception_handler
|
28
31
|
end
|
29
32
|
end
|
@@ -92,10 +95,46 @@ class GlobalErrorHandler::Redis
|
|
92
95
|
|
93
96
|
def clear_filters(key)
|
94
97
|
FILTER_FIELDS.each do |field|
|
98
|
+
retry_count = 0
|
95
99
|
field_value = build_filter_value(redis.hget key, field)
|
96
|
-
|
97
|
-
|
100
|
+
begin
|
101
|
+
filter_keys_for(field, field_value).each do |filter_key|
|
102
|
+
redis.lrem filter_key, 1, key
|
103
|
+
end
|
104
|
+
rescue
|
105
|
+
field_value = ''
|
106
|
+
retry if (retry_count += 1) < 2
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def cleanup_database_dependencies!
|
112
|
+
total_exceptions_count = exceptions_count
|
113
|
+
total_exception_keys_count = redis.keys(exception_key('*')).size
|
114
|
+
if total_exceptions_count > total_exception_keys_count
|
115
|
+
puts "==> Database dependency is broken. Need to fix it!"
|
116
|
+
start = 0
|
117
|
+
per_page = 500
|
118
|
+
exception_keys_to_be_cleaned_up = []
|
119
|
+
valid_chunks_count = 0
|
120
|
+
cleanup_count = exception_keys_to_be_cleaned_up.size
|
121
|
+
while total_exceptions_count > start
|
122
|
+
exception_keys(start, per_page).each do |redis_key|
|
123
|
+
exception_keys_to_be_cleaned_up.push redis_key unless redis.exists(redis_key)
|
124
|
+
end
|
125
|
+
if cleanup_count == (cleanup_count = exception_keys_to_be_cleaned_up.size)
|
126
|
+
valid_chunks_count += 1
|
127
|
+
end
|
128
|
+
break if valid_chunks_count > 3 #if three ranges in a row are consistent, treat database consistency and finish looping
|
129
|
+
start += per_page
|
130
|
+
end
|
131
|
+
|
132
|
+
puts "*** found #{exception_keys_to_be_cleaned_up.count} broken dependency keys."
|
133
|
+
exception_keys_to_be_cleaned_up.each do |redis_key|
|
134
|
+
delete_dependencies(redis_key) rescue next
|
98
135
|
end
|
136
|
+
else
|
137
|
+
puts "==> Database dependency is OK. No need to fix it!"
|
99
138
|
end
|
100
139
|
end
|
101
140
|
|
@@ -11,7 +11,7 @@ namespace :global_error_handler do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
desc 'Unsubscribe from expired keyevent notifications'
|
14
|
-
task :
|
14
|
+
task unsubscribe_from_expired: :environment do
|
15
15
|
puts '*** pid file does not exist!' or next unless File.exists?(pid_file)
|
16
16
|
process_id = File.read(pid_file).to_i
|
17
17
|
begin
|
@@ -29,6 +29,13 @@ namespace :global_error_handler do
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
desc 'Clean database dependencies for exception keys'
|
33
|
+
task cleanup_database_dependencies: :environment do
|
34
|
+
puts '** starting CleanUp process...'
|
35
|
+
GlobalErrorHandler::Redis.cleanup_database_dependencies!
|
36
|
+
puts '** completed CleanUp process.'
|
37
|
+
end
|
38
|
+
|
32
39
|
def pid_file
|
33
40
|
@pid_file ||= File.expand_path('./tmp/pids/global_error_handler_subscription.pid')
|
34
41
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: global_error_handler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrii Rudenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,6 +97,7 @@ files:
|
|
97
97
|
- LICENSE.txt
|
98
98
|
- README.md
|
99
99
|
- Rakefile
|
100
|
+
- config/recipes/global_error_handler.rb
|
100
101
|
- config/redis_example.yml
|
101
102
|
- global_error_handler.gemspec
|
102
103
|
- lib/global_error_handler.rb
|