activehook-server 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/activehook/server/errors.rb +23 -6
- data/lib/activehook/server/manager.rb +26 -5
- data/lib/activehook/server/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec7b771869365076f1cf3dbabfe47776dcc3d685
|
4
|
+
data.tar.gz: 49c351e933c44e2bc253d8c9f000920f581ab409
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bc07465c80a02621a7a56be3c8ef409347b4e87ebb1071a7058b56a2dbc070683f462ff5715b14f756370b466fe86086c4f0292314265c1398616383cbb946f
|
7
|
+
data.tar.gz: ed4f26e1fb08076eb21e113b6cbb9388dc1f23817b0b4f16580502bf0cc7155d8c7ab87c74c0a56d0efb9c1c938c2faa0213e38ffac20092bdc1cedc485da2db
|
@@ -1,12 +1,29 @@
|
|
1
1
|
module ActiveHook
|
2
2
|
module Server
|
3
3
|
module Errors
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
class Base < StandardError
|
5
|
+
def initialize(msg = nil)
|
6
|
+
@message = msg
|
7
|
+
log_error
|
8
|
+
end
|
9
|
+
|
10
|
+
def message
|
11
|
+
"The following error occured: #{@message}"
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def log_error
|
17
|
+
ActiveHook::Server.log.err(@message)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Config < Base; end
|
22
|
+
class Message < Base; end
|
23
|
+
class HTTP < Base; end
|
24
|
+
class Send < Base; end
|
25
|
+
class Manager < Base; end
|
26
|
+
class Worker < Base; end
|
10
27
|
end
|
11
28
|
end
|
12
29
|
end
|
@@ -10,6 +10,7 @@ module ActiveHook
|
|
10
10
|
def initialize(options = {})
|
11
11
|
options.each { |key, value| send("#{key}=", value) }
|
12
12
|
@master = Process.pid
|
13
|
+
@forks = []
|
13
14
|
at_exit { shutdown }
|
14
15
|
end
|
15
16
|
|
@@ -27,7 +28,9 @@ module ActiveHook
|
|
27
28
|
# Shutsdown our Worker processes.
|
28
29
|
#
|
29
30
|
def shutdown
|
30
|
-
@forks.
|
31
|
+
unless @forks.empty?
|
32
|
+
@forks.each { |w| Process.kill('SIGINT', w[:pid].to_i) }
|
33
|
+
end
|
31
34
|
Process.kill('SIGINT', @master)
|
32
35
|
end
|
33
36
|
|
@@ -36,7 +39,6 @@ module ActiveHook
|
|
36
39
|
# Create the specified number of workers and starts them
|
37
40
|
#
|
38
41
|
def create_workers
|
39
|
-
@forks = []
|
40
42
|
@workers.times do |id|
|
41
43
|
pid = fork { Worker.new(@options.merge(id: id)).start }
|
42
44
|
@forks << { id: id, pid: pid }
|
@@ -54,9 +56,28 @@ module ActiveHook
|
|
54
56
|
# connection pool by pinging Redis.
|
55
57
|
#
|
56
58
|
def validate!
|
57
|
-
|
58
|
-
|
59
|
-
|
59
|
+
validate_redis
|
60
|
+
validate_workers
|
61
|
+
validate_options
|
62
|
+
end
|
63
|
+
|
64
|
+
def validate_redis
|
65
|
+
ActiveHook::Server.redis.with { |c| c.ping && c.quit }
|
66
|
+
rescue
|
67
|
+
msg = 'Cound not connect to Redis.'
|
68
|
+
ActiveHook::Server.log.err(msg)
|
69
|
+
raise Errors::Manager, msg
|
70
|
+
end
|
71
|
+
|
72
|
+
def validate_workers
|
73
|
+
return if @workers.is_a?(Integer)
|
74
|
+
msg = 'Workers must be an Integer.'
|
75
|
+
raise Errors::Manager, msg
|
76
|
+
end
|
77
|
+
|
78
|
+
def validate_options
|
79
|
+
return if @options.is_a?(Hash)
|
80
|
+
raise Errors::Manager, 'Options must be a Hash.'
|
60
81
|
end
|
61
82
|
end
|
62
83
|
end
|