ak47 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ak47.rb +25 -20
- data/lib/ak47/version.rb +1 -1
- metadata +3 -3
data/lib/ak47.rb
CHANGED
@@ -3,32 +3,37 @@ require 'shell_tools'
|
|
3
3
|
require "ak47/version"
|
4
4
|
|
5
5
|
module Ak47
|
6
|
+
Reload = Class.new(RuntimeError)
|
7
|
+
|
6
8
|
class << self
|
7
9
|
def run(*argv)
|
8
10
|
command = ShellTools.escape(argv)
|
9
|
-
|
10
|
-
|
11
|
-
kill_subprocess = proc do
|
12
|
-
begin
|
13
|
-
Process.kill("INT", @pid) if @pid
|
14
|
-
rescue Errno::ESRCH
|
15
|
-
end
|
16
|
-
end
|
17
|
-
trap("INT", &kill_subprocess)
|
18
|
-
at_exit(&kill_subprocess)
|
19
|
-
listener = Guard::Listener.select_and_init(:watchdir => Dir.pwd, :watch_all_modifications => true)
|
11
|
+
watch_dir = Dir.pwd
|
12
|
+
listener = Guard::Listener.select_and_init(:watchdir => watch_dir, :watch_all_modifications => true)
|
20
13
|
listener.on_change {
|
21
|
-
|
22
|
-
Process.kill("INT", @pid) if @pid
|
14
|
+
Thread.main.raise Reload
|
23
15
|
}
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
16
|
+
Thread.new { listener.start }
|
17
|
+
|
18
|
+
at_exit { Process.kill("INT", @pid) rescue nil if @pid }
|
19
|
+
|
20
|
+
puts "[Starting ak47 #{VERSION} in #{watch_dir.inspect}]"
|
21
|
+
loop do
|
22
|
+
begin
|
23
|
+
puts "[Running... #{Time.new.to_s}]"
|
24
|
+
puts "# #{command}"
|
25
|
+
@pid = fork { exec(command) }
|
26
|
+
_, status = Process.waitpid2(@pid)
|
27
|
+
if status.success?
|
28
|
+
puts "[Terminated, waiting for file system change]"
|
29
|
+
sleep
|
30
|
+
else
|
31
|
+
puts "[Terminated abnormally (#{status.inspect}), retrying in 5s]"
|
32
|
+
sleep 5
|
33
|
+
end
|
34
|
+
rescue Reload
|
35
|
+
puts "[Reloading... #{Time.new.to_s}]"
|
30
36
|
end
|
31
|
-
Process.waitpid(@pid)
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
data/lib/ak47/version.rb
CHANGED
metadata
CHANGED