lib/tailog.rb in tailog-0.5.9 vs lib/tailog.rb in tailog-0.6.0

- old
+ new

@@ -18,10 +18,14 @@ attr_accessor :log_path, :request_id def server_hostname @server_hostname ||= Socket.gethostname end + + def process_uuid + @process_uuid ||= SecureRandom.uuid + end end self.log_path = File.expand_path("log", Dir.pwd) class App < Sinatra::Base @@ -60,10 +64,11 @@ content = erb :error, locals: { error: error }, layout: false end { server_hostname: Tailog.server_hostname, + process_uuid: Tailog.process_uuid, file_size: file_size, content: content }.to_json end @@ -74,14 +79,23 @@ get '/script' do erb :'script/index' end post '/script' do - content = erb :"script/#{params[:type]}", locals: { script: params[:script] }, layout: false - - { + result = { server_hostname: Tailog.server_hostname, - content: content - }.to_json + process_uuid: Tailog.process_uuid + } + + ignore_content = false + if params[:broadcast] + instance_id = result[:instance_id] = params[:type] == "bash" ? Tailog.server_hostname : Tailog.process_uuid + discovered_instances = params[:discovered_instances] || [] + ignore_content = true if discovered_instances.include? instance_id + end + + result[:content] = erb :"script/#{params[:type]}", locals: { script: params[:script] }, layout: false unless ignore_content + + result.to_json end end end