Last active
January 2, 2016 09:48
-
-
Save kylewelsby/8285170 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'redis' | |
require 'open3' | |
class Finder | |
def redis | |
Redis.new | |
end | |
def listen_for_terminate(id) | |
Thread.new do | |
loop do | |
puts 'checking' | |
if redis.get("terminate:#{id}") | |
puts "KILL!!!!" | |
redis.del("terminate:#{id}") | |
Process.kill('INT', Process.pid) | |
end | |
sleep 0.5 | |
end | |
end | |
end | |
def perform | |
Open3.popen3('find ~') do |stdin, stdout, stderr, wait_thr| | |
puts stdout.read | |
end | |
end | |
end | |
Finder.new.tap do |train| | |
train.listen_for_terminate(1) | |
train.perform | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment