Navigation Menu

Skip to content

Commit

Permalink
serf: extract "serf XXX(not agent)" code as a class
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jan 5, 2015
1 parent 29f47e4 commit eb01df2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 25 deletions.
31 changes: 6 additions & 25 deletions lib/droonga/serf.rb
@@ -1,4 +1,4 @@
# Copyright (C) 2014 Droonga Project
# Copyright (C) 2014-2015 Droonga Project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
Expand All @@ -15,14 +15,14 @@

require "json"
require "coolio"
require "open3"

require "droonga/path"
require "droonga/loggable"
require "droonga/catalog_loader"
require "droonga/node_metadata"
require "droonga/serf_downloader"
require "droonga/serf_agent"
require "droonga/serf_command"
require "droonga/line_buffer"
require "droonga/safe_file_writer"
require "droonga/service_installation"
Expand Down Expand Up @@ -183,10 +183,10 @@ def find_system_serf
end

def run_once(command, *options)
process = SerfProcess.new(@serf, command,
"-rpc-addr", rpc_address,
*options)
process.run_once
command = Command.new(@serf, command,
"-rpc-addr", rpc_address,
*options)
command.run
end

def additional_options_from_payload(payload)
Expand Down Expand Up @@ -243,24 +243,5 @@ def detect_other_hosts
def log_tag
"serf"
end

class SerfProcess
include Loggable

def initialize(serf, command, *options)
@serf = serf
@command = command
@options = options
end

def run_once
stdout, stderror, status = Open3.capture3(@serf, @command, *@options, :pgroup => true)
{
:result => stdout,
:error => stderror,
:status => status,
}
end
end
end
end
45 changes: 45 additions & 0 deletions lib/droonga/serf_command.rb
@@ -0,0 +1,45 @@
# Copyright (C) 2014-2015 Droonga Project
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

require "open3"

require "droonga/loggable"

module Droonga
class Serf
class Command
include Loggable

def initialize(serf, command, *options)
@serf = serf
@command = command
@options = options
end

def run
stdout, stderror, status = Open3.capture3(@serf, @command, *@options, :pgroup => true)
{
:result => stdout,
:error => stderror,
:status => status,
}
end

def log_tag
"serf[#{@command}]"
end
end
end
end

0 comments on commit eb01df2

Please sign in to comment.