opal-up 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/up_ext/up_ext.c +4 -0
- data/lib/up/ruby/cluster.rb +15 -3
- data/lib/up/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb3a4f16540780758e686bbd53c9ab5467b85988bd83a990b05ab54b124c2d2d
|
4
|
+
data.tar.gz: 292c74cb7b0771cf807af2b1ebc221707f2b92bd28ca2e1271038b242aa94fc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fbbd939aa7c268d503953c9d7b36d92071c23ae498df1c948acb6886007a66eb60218766528fbb6f5fe1016cdd77890a039533c40fbe3baad8594cca77f8e2d
|
7
|
+
data.tar.gz: da01a9584cd43ec5d5c2b97cad04c2bf6895ec029e5e34f4614a9381010788009c97f09c5b8e832913befbb6fb2b3b9157f1baeeff280cbd3e527bb61b4450e6
|
data/ext/up_ext/up_ext.c
CHANGED
@@ -26,6 +26,7 @@ static ID at_instance;
|
|
26
26
|
static ID at_member_id;
|
27
27
|
static ID at_members;
|
28
28
|
static ID at_open;
|
29
|
+
static ID at_port;
|
29
30
|
static ID at_protocol;
|
30
31
|
static ID at_secret;
|
31
32
|
static ID at_server;
|
@@ -629,6 +630,8 @@ static VALUE up_server_init(int argc, VALUE *argv, VALUE self) {
|
|
629
630
|
s->port = rport;
|
630
631
|
s->logger = rargs[3];
|
631
632
|
|
633
|
+
rb_ivar_set(self, at_port, s->port);
|
634
|
+
|
632
635
|
return self;
|
633
636
|
}
|
634
637
|
|
@@ -969,6 +972,7 @@ void Init_up_ext(void) {
|
|
969
972
|
at_member_id = rb_intern("@member_id");
|
970
973
|
at_members = rb_intern("@members");
|
971
974
|
at_open = rb_intern("@open");
|
975
|
+
at_port = rb_intern("@port");
|
972
976
|
at_protocol = rb_intern("@protocol");
|
973
977
|
at_secret = rb_intern("@secret");
|
974
978
|
at_server = rb_intern("@server");
|
data/lib/up/ruby/cluster.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# backtick_javascript: true
|
2
2
|
require 'etc'
|
3
3
|
require 'random/formatter'
|
4
|
+
require 'socket'
|
4
5
|
require 'up_ext'
|
5
6
|
|
6
7
|
module Up
|
@@ -38,8 +39,10 @@ module Up
|
|
38
39
|
|
39
40
|
def install_signal_handlers
|
40
41
|
Signal.trap('CHLD') do
|
41
|
-
|
42
|
-
|
42
|
+
unless members_alive?
|
43
|
+
warn "\nError: a cluster worker died!"
|
44
|
+
kill_members
|
45
|
+
end
|
43
46
|
end
|
44
47
|
Signal.trap('INT') do
|
45
48
|
warn "\nReceived CTRL-C!"
|
@@ -49,7 +52,7 @@ module Up
|
|
49
52
|
|
50
53
|
def kill_members
|
51
54
|
Signal.trap('CHLD', 'IGNORE')
|
52
|
-
STDERR.print "Stopping workers: "
|
55
|
+
STDERR.print "Stopping all workers: "
|
53
56
|
@members.each do |mid|
|
54
57
|
Process.kill('INT', mid) rescue nil
|
55
58
|
STDERR.print '.'
|
@@ -58,6 +61,15 @@ module Up
|
|
58
61
|
warn "\nCluster stopped."
|
59
62
|
Signal.trap('CHLD', 'DEFAULT')
|
60
63
|
end
|
64
|
+
|
65
|
+
def members_alive?
|
66
|
+
@workers.times do |i|
|
67
|
+
TCPSocket.new('localhost', @port + i + 1).close
|
68
|
+
end
|
69
|
+
true
|
70
|
+
rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL
|
71
|
+
false
|
72
|
+
end
|
61
73
|
end
|
62
74
|
end
|
63
75
|
end
|
data/lib/up/version.rb
CHANGED