nerve-easy 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a974ad4d3cd94de4611e6ec03a7755b668040c25
4
- data.tar.gz: 2901499eacfde352b4c7c9a9a259ef8636b84837
3
+ metadata.gz: 3f1172ddaceb46bdb683c4f020bb72da0a33f5aa
4
+ data.tar.gz: 8175a9366f11e5cb6fafdb6af901542587c80829
5
5
  SHA512:
6
- metadata.gz: 15b8b533188b8073244019a6946af77b1ad9dfe9d88890518779eb42d4ed0471189b5430b669d4816177d523ef00b64ef90eba4e79fd2bec954a740f4b6d1b93
7
- data.tar.gz: a1ebdd5dd85fb680833457d7e1776feffc326450b8f9d8691b1b68dcce5ab75f56e68a1b51282a24300e658607d7661c6db36c132b24a556c6dc06e8320eab62
6
+ metadata.gz: dbe81a1c060a2c107ea9cad1acbc10e3e8892ef2f7b759345933e4d62f47316a85ec239b282b45c33a4d8950d1a14710462f5419c85de2eb9bf79f6c64e0ff78
7
+ data.tar.gz: f19e88838d735607c11786870c10b58e9a29ff72189b88218af8a3eecb6760a907b9465d8cda2d8e01128bfda09e1eac6271e761769b614707c88b4d8e502a3a
@@ -0,0 +1,15 @@
1
+ module Nerve
2
+ module Easy
3
+ module FixedInstanceId
4
+ class << self
5
+ def instance_id klass_name, size
6
+ @instance_ids ||= {}
7
+ @instance_ids[klass_name] ||= SecureRandom.hex(size)
8
+ end
9
+ end
10
+ def instance_id size=4
11
+ FixedInstanceId.instance_id @name, size
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ require "fake/hash"
2
+ require "nerve/easy/fixed_instance_id"
3
+
4
+ module Nerve
5
+ module Easy
6
+ class Nerve
7
+ include Fake::Hash
8
+ include FixedInstanceId
9
+ def initialize
10
+ @services = {}
11
+ end
12
+ def announce service
13
+ @services[service.name] = service
14
+ end
15
+ def to_nerve
16
+ {
17
+ "instance_id" => instance_id,
18
+ "services" => @services.collect{|n,c| [n,c] }.to_h,
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,15 +1,12 @@
1
1
  require "fake/hash"
2
+ require "nerve/easy/fixed_instance_id"
2
3
 
3
4
  module Nerve
4
5
  module Easy
5
6
  class Reporter
6
7
  include Fake::Hash
7
- class << self
8
- def instance_id size=4
9
- @instance_id ||= SecureRandom.hex(size)
10
- end
11
- end
12
- attr_accessor :zk_hosts, :zk_path, :host, :port
8
+ include FixedInstanceId
9
+ attr_accessor :zk_hosts, :zk_path, :host, :port, :name
13
10
  def initialize params={}
14
11
  @zk_hosts = params[:zk_hosts]
15
12
  @zk_hosts ||= [ "localhost:2181" ]
@@ -0,0 +1,61 @@
1
+ require "fake/hash"
2
+ require "nerve/easy/reporter"
3
+
4
+ module Nerve
5
+ module Easy
6
+ class Service < Reporter
7
+ attr_accessor :reporter_type, :interval, :rise, :fall, :type, :uri,
8
+ :registry, :customer, :application, :function, :suffix
9
+ def initialize params={}
10
+ super
11
+ @reporter_type = params[:reporter_type]
12
+ @reporter_type ||= "zookeeper"
13
+ @interval = params[:interval]
14
+ @interval ||= 2
15
+ @timeout = params[:timeout]
16
+ @timeout ||= 0.2
17
+ @rise = params[:rise]
18
+ @rise ||= 2
19
+ @fall = params[:fall]
20
+ @fall ||= 3
21
+ @type = params[:type]
22
+ @type ||= :tcp
23
+ @uri = params[:uri]
24
+ @registry = params[:registry]
25
+ @registry ||= "global"
26
+ @customer = params[:customer]
27
+ @customer ||= "global"
28
+ @application = params[:application]
29
+ @application ||= "global"
30
+ @function = params[:function]
31
+ @function ||= "global"
32
+ @suffix = params[:suffix]
33
+ @suffix ||= "global"
34
+ @name = params[:name]
35
+ unless @name
36
+ @name = "#{@customer}_#{@application}_#{@function}"
37
+ end
38
+ @zk_path = Pathname.new("/#{@registry}")
39
+ @zk_path = @zk_path.join(@customer,@application,@function,@suffix).to_s
40
+ end
41
+ def to_nerve
42
+ super.merge({
43
+ "reporter_type" => reporter_type,
44
+ "check_interval" => interval,
45
+ "checks" => checks
46
+ })
47
+ end
48
+ def checks
49
+ [
50
+ {
51
+ "timeout" => @timeout,
52
+ "rise" => @rise,
53
+ "fall" => @fall,
54
+ "type" => @type,
55
+ "uri" => @uri
56
+ }
57
+ ]
58
+ end
59
+ end
60
+ end
61
+ end
@@ -1,5 +1,5 @@
1
1
  module Nerve
2
2
  module Easy
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
data/lib/nerve/easy.rb CHANGED
@@ -1,2 +1,4 @@
1
1
  require "nerve/easy/version"
2
- require "nerve/easy/reporter"
2
+ require "nerve/easy/reporter"
3
+ require "nerve/easy/service"
4
+ require "nerve/easy/nerve"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nerve-easy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Kaufmann
@@ -67,7 +67,10 @@ files:
67
67
  - bin/console
68
68
  - bin/setup
69
69
  - lib/nerve/easy.rb
70
+ - lib/nerve/easy/fixed_instance_id.rb
71
+ - lib/nerve/easy/nerve.rb
70
72
  - lib/nerve/easy/reporter.rb
73
+ - lib/nerve/easy/service.rb
71
74
  - lib/nerve/easy/version.rb
72
75
  - nerve-easy.gemspec
73
76
  homepage: https://nerve.stei.gr/easy