Class: Nerve::Easy::Service

Inherits:
Reporter show all
Defined in:
lib/nerve/easy/service.rb

Instance Attribute Summary collapse

Attributes inherited from Reporter

#host, #name, #port, #zk_hosts, #zk_path

Instance Method Summary collapse

Methods included from FixedInstanceId

#instance_id, instance_id

Constructor Details

#initialize(params = {}) ⇒ Service

Returns a new instance of Service.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/nerve/easy/service.rb', line 10

def initialize params={}
  super
  @reporter_type   = params[:reporter_type]
  @reporter_type ||= "zookeeper"
  @interval        = params[:interval]
  @interval      ||= 2
  @timeout         = params[:timeout]
  @timeout       ||= 0.2
  @rise            = params[:rise]
  @rise          ||= 2
  @fall            = params[:fall]
  @fall          ||= 3
  @type            = params[:type]
  @type          ||= :tcp
  @type            = @type.to_s
  @uri             = params[:uri]
  @registry        = params[:registry]
  @registry      ||= "nerve"
  @customer        = params[:customer]
  @customer      ||= "global"
  @application     = params[:application]
  @application   ||= "application"
  @function        = params[:function]
  @function      ||= "function"
  @suffix          = params[:suffix]
  @suffix        ||= "services"
  @name            = params[:name]
  @name = "#{@customer}_#{@application}_#{@function}" unless @name
  @zk_path         = nil
  @zk_path         = params[:zk_path]
  @zk_path ||= Pathname.new("/#{@registry}").join(@customer,@application,@function,@suffix).to_s
end

Instance Attribute Details

#application ⇒ Object

Returns the value of attribute application.



8
9
10
# File 'lib/nerve/easy/service.rb', line 8

def application
  @application
end

#customer ⇒ Object

Returns the value of attribute customer.



8
9
10
# File 'lib/nerve/easy/service.rb', line 8

def customer
  @customer
end

#fall ⇒ Object

Returns the value of attribute fall.



8
9
10
# File 'lib/nerve/easy/service.rb', line 8

def fall
  @fall
end

#function ⇒ Object

Returns the value of attribute function.



8
9
10
# File 'lib/nerve/easy/service.rb', line 8

def function
  @function
end

#interval ⇒ Object

Returns the value of attribute interval.



8
9
10
# File 'lib/nerve/easy/service.rb', line 8

def interval
  @interval
end

#registry ⇒ Object

Returns the value of attribute registry.



8
9
10
# File 'lib/nerve/easy/service.rb', line 8

def registry
  @registry
end

#reporter_type ⇒ Object

Returns the value of attribute reporter_type.



8
9
10
# File 'lib/nerve/easy/service.rb', line 8

def reporter_type
  @reporter_type
end

#rise ⇒ Object

Returns the value of attribute rise.



8
9
10
# File 'lib/nerve/easy/service.rb', line 8

def rise
  @rise
end

#suffix ⇒ Object

Returns the value of attribute suffix.



8
9
10
# File 'lib/nerve/easy/service.rb', line 8

def suffix
  @suffix
end

#type ⇒ Object

Returns the value of attribute type.



8
9
10
# File 'lib/nerve/easy/service.rb', line 8

def type
  @type
end

#uri ⇒ Object

Returns the value of attribute uri.



8
9
10
# File 'lib/nerve/easy/service.rb', line 8

def uri
  @uri
end

Instance Method Details

#checks ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/nerve/easy/service.rb', line 49

def checks
  [
    {
      "timeout" => @timeout,
      "rise"    => @rise,
      "fall"    => @fall,
      "type"    => @type,
      "uri"     => @uri
    }
  ]
end

#to_nerve ⇒ Object



42
43
44
45
46
47
48
# File 'lib/nerve/easy/service.rb', line 42

def to_nerve
  super.merge({
    "reporter_type"  => reporter_type,
    "check_interval" => interval,
    "checks"         => checks
  })
end