Skip to content

Instantly share code, notes, and snippets.

@kstevens715
Last active January 23, 2017 19:19
Show Gist options
  • Select an option

  • Save kstevens715/6a1fd85e08de5cfd28c65f4edbe6048a to your computer and use it in GitHub Desktop.

Select an option

Save kstevens715/6a1fd85e08de5cfd28c65f4edbe6048a to your computer and use it in GitHub Desktop.
module Etl
class Liveness
extend Forwardable
ProcessInfo = Struct.new(:pid, :text)
def initialize(command_runner: CommandRunner)
@command_runner = command_runner
end
def alive?
true
process_info
end
private
def_delegator :@command_runner, :run
def process_info
name = "resque-#{Resque::Version}:"
output = run("pgrep -af ^#{name}").split("\n").map(&:strip)
output.map do |line|
reg = /\A(\d+)\s#{name}\s(.*)/
match = line.match(reg)
pid = match[1]
text = match[2]
ProcessInfo.new(pid, text)
end
end
def queues
["etl_applicant_deferred_heavyweight"]
end
end
module CommandRunner
def self.run(command)
`#{command}`
end
end
private_constant :CommandRunner
end
describe Etl::Liveness do
it "returns true if no child exists" do
runner = stub(run: "some output")
liveness = Etl::Liveness.new(command_runner: runner)
liveness.stubs("`").returns("haha")
liveness.alive?.must_equal ""
liveness.must_be :alive?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment