global_error_handler 1.1.0 → 1.2.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: 316acd20a326cf7e663729b28bf45fb57e7798a6
4
- data.tar.gz: 66ee6184856edc3c4d1d0ff26f9c029e057585f8
3
+ metadata.gz: 9754eb3b73eaff7706b3f65e5c5f4a45b454d874
4
+ data.tar.gz: c45f97699e47d4e6873b17ecd788c1376316d465
5
5
  SHA512:
6
- metadata.gz: d7119d94b20bdf97529e0e1a821b6fb9ffb3a5c7206a565f7934bfc5df66bba2662dd877854fd4b81f8417715745a0c33e6b775b5f5f518b1ecbdd286ce932d2
7
- data.tar.gz: f1e1f8fd2da47793a30ea992e36d09e4203a45f1fe4337c410e8a0617f638c47173c6ef01464c8cfc8bc6184202a9be2fc7b31d53cafff3b74fcc0d601a782f4
6
+ metadata.gz: 8975a6cc714719315e097adc6fcd78142b24529bb5cda52b2c2ac26dd1bc325a3132c8cbd68c855d0a39b489bc9e88d9e94782dd52dd1f7bec07a77ddf8984c8
7
+ data.tar.gz: 373dcdd22986e947b9a8ae6286e5aca4196b8f7afb6b911338e29705bf7073af1630ed0911019535589a425d406e80bfa0bccfa58ad42199f932ea3bca03f9d8
data/README.md CHANGED
@@ -19,7 +19,7 @@ It adds Exceptions tab to Redis Web server in case to view, filter, delete or tr
19
19
 
20
20
  Add this line to your application's Gemfile:
21
21
 
22
- gem 'global_error_handler'
22
+ gem 'global_error_handler', '~> 1.2.3'
23
23
 
24
24
  And then execute:
25
25
 
@@ -4,12 +4,48 @@
4
4
  # /etc/init.d/<%= application %>_geh_subscription
5
5
 
6
6
  start() {
7
- su - <%= user %> -c "cd <%= current_path %>; PATH=$PATH:/home/<%= user %>/.rvm/bin; RAILS_ENV=<%= rails_env %> nohup rvm <%= rvm_ruby_string %> do rake global_error_handler:cleanup_database_dependencies >/dev/null 2>&1 & sleep 2"
8
- su - <%= user %> -c "cd <%= current_path %>; PATH=$PATH:/home/<%= user %>/.rvm/bin; RAILS_ENV=<%= rails_env %> nohup rvm <%= rvm_ruby_string %> do rake global_error_handler:subscribe_to_expired >/dev/null 2>&1 & sleep 3"
7
+ pid_file=<%= shared_path %>/pids/global_error_handler_subscription.pid
8
+ if [ -e "$pid_file" ] && \
9
+ kill -0 `cat $pid_file` >/dev/null 2>&1; then
10
+ echo GEH Subscription is already running. Quiting...
11
+ else
12
+ rm -f $pid_file >/dev/null 2>&1
13
+ echo GEH Subscription is not running. Executing start command...
14
+ su - <%= user %> -c "cd <%= current_path %>; PATH=$PATH:/home/<%= user %>/.rvm/bin; \
15
+ RAILS_ENV=<%= rails_env %> nohup rvm <%= rvm_ruby_string %> do rake global_error_handler:cleanup_database_dependencies >/dev/null 2>&1 & sleep 2"
16
+ su - <%= user %> -c "cd <%= current_path %>; PATH=$PATH:/home/<%= user %>/.rvm/bin; \
17
+ RAILS_ENV=<%= rails_env %> nohup rvm <%= rvm_ruby_string %> do rake global_error_handler:subscribe_to_expired >/dev/null 2>&1 & sleep 3"
18
+ echo done
19
+ fi
9
20
  }
10
21
 
11
22
  stop() {
12
- su - <%= user %> -c "cd <%= current_path %>; PATH=$PATH:<%= rvm_bin_path %>; RAILS_ENV=<%= rails_env %> rvm <%= rvm_ruby_string %> do rake global_error_handler:unsubscribe_from_expired"
23
+ pid_file=<%= shared_path %>/pids/global_error_handler_subscription.pid
24
+ if [ -e "$pid_file" ] && \
25
+ kill -0 `cat $pid_file` >/dev/null 2>&1; then
26
+ echo Stopping GEH Subscription...
27
+ kill -s INT `cat $pid_file`
28
+ tries_count=8
29
+ success=0
30
+ while [ $((tries_count-=1)) -ge 0 ]; do
31
+ if [ -e "$pid_file" ] >/dev/null 2>&1; then
32
+ sleep 1
33
+ else
34
+ success=1
35
+ break
36
+ fi
37
+ done
38
+ if [ $success -eq 0 ]; then
39
+ echo "killing GEH Subscription process..."
40
+ kill -s KILL `cat $pid_file`
41
+ rm -f $pid_file >/dev/null 2>&1
42
+ else
43
+ echo GEH Subscription has been stopped successfully.
44
+ fi
45
+ else
46
+ rm -f $pid_file >/dev/null 2>&1
47
+ echo GEH Subscription is not running.
48
+ fi
13
49
  }
14
50
 
15
51
  case "$1" in
@@ -35,7 +35,7 @@ module GlobalErrorHandler
35
35
  puts "##{Process.pid}: #{error}, retrying in 1s"
36
36
  sleep 1
37
37
  retry
38
- rescue Interrupt => error
38
+ rescue Interrupt
39
39
  puts "##{Process.pid}: unsubscribing..."
40
40
  unsubscribe!
41
41
  redis.quit
@@ -1,3 +1,3 @@
1
1
  module GlobalErrorHandler #:nodoc:
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.3'
3
3
  end
@@ -1,39 +1,55 @@
1
1
  namespace :global_error_handler do
2
2
  desc 'Subscribe to expired keyevent notifications'
3
3
  task subscribe_to_expired: :environment do
4
- puts('*** pid file exists!') || next if File.exist?(pid_file)
4
+ if pid_file_exists?
5
+ begin
6
+ Process.kill 0, process_id
7
+ puts '*** already running!'
8
+ next
9
+ rescue Errno::ESRCH
10
+ end
11
+ end
12
+
5
13
  File.open(pid_file, 'w') { |f| f.puts Process.pid }
14
+
6
15
  begin
7
16
  GlobalErrorHandler::RedisNotificationSubscriber.subscribe!
8
17
  ensure
9
- begin
10
- File.unlink pid_file
11
- rescue
12
- nil
13
- end
18
+ File.unlink(pid_file) rescue nil
14
19
  end
15
20
  end
16
21
 
17
22
  desc 'Unsubscribe from expired keyevent notifications'
18
23
  task unsubscribe_from_expired: :environment do
19
- puts('*** pid file does not exist!') || next unless File.exist?(pid_file)
20
- process_id = File.read(pid_file).to_i
24
+ puts('*** pid file does not exist!') || next unless pid_file_exists?
25
+
21
26
  begin
22
27
  Process.kill 0, process_id
23
28
  GlobalErrorHandler::RedisNotificationSubscriber.unsubscribe!
24
- puts "** Terminating ##{process_id}..."
25
- Timeout.timeout(10) { Process.kill 15, process_id }
26
- rescue Timeout::Error
27
- puts "** Killing ##{process_id} after waiting for 10 seconds..."
28
- Process.kill 9, process_id
29
+
30
+ term_signals = [2, 3, 15, 9].to_enum
31
+ begin
32
+ puts "** Sending signal #{term_signals.peek} to ##{process_id}..."
33
+ Process.kill(term_signals.next, process_id)
34
+
35
+ i_try = 0
36
+ while i_try <= 3
37
+ Process.kill 0, process_id
38
+ i_try += 1
39
+ sleep 1
40
+ raise RetryIteration if i_try == 3
41
+ end
42
+ rescue RetryIteration
43
+ retry
44
+ rescue StopIteration
45
+ puts '*** failed to stop a process!'
46
+ rescue Errno::ESRCH, Errno::ENOENT
47
+ puts '*** successfully stopped!'
48
+ end
29
49
  rescue Errno::ESRCH
30
50
  puts "** No such process ##{process_id}. Exiting..."
31
51
  ensure
32
- begin
33
- File.unlink pid_file
34
- rescue
35
- nil
36
- end
52
+ File.unlink(pid_file) rescue nil
37
53
  end
38
54
  end
39
55
 
@@ -44,7 +60,27 @@ namespace :global_error_handler do
44
60
  puts '** completed CleanUp process.'
45
61
  end
46
62
 
63
+ class RetryIteration < StandardError; end
64
+
65
+ def pid_location
66
+ pid_dir = [
67
+ File.join(Rails.root, '..', 'shared', 'pids'),
68
+ File.join(Rails.root, '..', '..', 'shared', 'pids'),
69
+ File.join(Rails.root, 'tmp', 'pids')
70
+ ].detect { |dir_name| Dir.exist?(dir_name) }
71
+
72
+ File.expand_path pid_dir
73
+ end
74
+
47
75
  def pid_file
48
- @pid_file ||= File.expand_path('./tmp/pids/global_error_handler_subscription.pid')
76
+ @pid_file ||= File.join(pid_location, 'global_error_handler_subscription.pid')
77
+ end
78
+
79
+ def process_id
80
+ File.read(pid_file).to_i
81
+ end
82
+
83
+ def pid_file_exists?
84
+ File.exist? pid_file
49
85
  end
50
86
  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: 1.1.0
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrii Rudenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-23 00:00:00.000000000 Z
11
+ date: 2016-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler