Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/nerve.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"zk_hosts": ["localhost:2181"],
"zk_path": "/nerve/services/your_http_service/services",
"check_interval": 2,
"sequential": false,
"checks": [
{
"type": "http",
Expand Down
20 changes: 15 additions & 5 deletions lib/nerve/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,18 @@ def initialize(opts)
raise ArgumentError, "you need to specify required argument #{required}" unless opts[required]
end

defaults = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no reason to do this; just do an || on the line where you set @sequential

:sequential => false,
}
opts = defaults.merge(opts)

@path = opts['hosts'].shuffle.join(',') + opts['path']
@data = parse_data(opts['data'] || '')
@key = opts['key']
@key.insert(0,'/') unless @key[0] == '/'
@sequential = opts['sequential']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should do opts['sequential'] || false here

@key.insert('-') if @sequential
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not, i added it to help visualize the sequence and separate it from the port

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the '-' is inserted to help visualize the sequence and separate from the port in the node path/key

@full_key = @key
end

def start()
Expand All @@ -23,7 +31,7 @@ def start()
log.info "nerve: successfully created zk connection to #{@path}"
end

def report_up()
def report_up
zk_save
end

Expand All @@ -43,15 +51,17 @@ def ping?
private

def zk_delete
@zk.delete(@key, :ignore => :no_node)
@zk.delete(@full_key, :ignore => :no_node)
end

def zk_save
log.debug "nerve: writing data #{@data.class} to zk at #{@key} with #{@data.inspect}"
log.debug "nerve: writing data #{@data.class} to zk at #{@key} with #{@data.inspect} and sequential
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would put weird whitespace in the debug message; you should do a continuation line instead -- i prefer the style where you end the line with a " \ and then start the next line with an indent and a new "

flag is #{@sequential}"
begin
@zk.set(@key,@data)
@zk.set(@full_key, @data)
rescue ZK::Exceptions::NoNode => e
@zk.create(@key,:data => @data, :mode => :ephemeral)
@full_key = @zk.create(@key,:data => @data, :ephemeral => true,
:sequential => @sequential)
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/nerve/service_watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def initialize(service={})
'path' => service['zk_path'],
'key' => "#{service['instance_id']}_#{@name}",
'data' => {'host' => service['host'], 'port' => service['port']},
'sequential' => service['sequential'] | false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you meant || here instead of | ?

})

# instantiate the checks for this service
Expand Down