activehook-server 0.1.3 → 0.1.4

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: b80925d2c8f3f969329dd4f904a6687364b864c9
4
- data.tar.gz: 79f29100344fb84d475397ac7a62aede31b7c5ae
3
+ metadata.gz: ec7b771869365076f1cf3dbabfe47776dcc3d685
4
+ data.tar.gz: 49c351e933c44e2bc253d8c9f000920f581ab409
5
5
  SHA512:
6
- metadata.gz: a346b717d2a4f8379c54ea8042ebde7ebd227058e4ea9ef9b3b7a3af7458645a611c11809deb1913652fb66657f8de3d429d485a17620b9a518855abd1dc8e98
7
- data.tar.gz: 84a1a32edfac8b9c4ab6d1c089a365e4dc88ecfad66c3c5fc33b8b82d851cf48771c69fb98784e808d8a962664826e5f2de6ebb0d9f27bb1e350ae18334bcc41
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 Config < StandardError; end
5
- class Message < StandardError; end
6
- class HTTP < StandardError; end
7
- class Send < StandardError; end
8
- class Server < StandardError; end
9
- class Worker < StandardError; end
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.each { |w| Process.kill('SIGINT', w[:pid].to_i) }
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
- raise Errors::Server, 'Cound not connect to Redis.' unless ActiveHook::Server.redis.with { |c| c.ping && c.quit }
58
- raise Errors::Server, 'Workers must be an Integer.' unless @workers.is_a?(Integer)
59
- raise Errors::Server, 'Options must be a Hash.' unless @options.is_a?(Hash)
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
@@ -1,6 +1,6 @@
1
1
  module ActiveHook
2
2
  module Server
3
- VERSION = '0.1.3'
3
+ VERSION = '0.1.4'
4
4
  CODENAME = 'Fat Sparrow'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activehook-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Sweeting