forked from suitmedia/kirk
/
run
65 lines (54 loc) · 1.29 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env ruby
$:.unshift File.expand_path('../../lib', __FILE__)
require "kirk"
require "uri"
require "fileutils"
require "net/http"
def redeploy(path)
FileUtils.touch File.expand_path("../#{path}/REVISION", __FILE__)
end
def background(int = 1, iterations = nil)
t = Thread.new do
while iterations.nil? || iterations > 0
iterations -= 1 if iterations
sleep int
yield
end
end
t.abort_on_exception = true
THREADS << t
end
THREADS = []
SERVER = Kirk::Server.build File.expand_path("../Kirkfile", __FILE__)
SERVER.start
unless ARGV.include?("--no-redeploys")
background 2 do
redeploy "redeploys"
end
end
unless ARGV.include?("--no-train-app")
# Create widgets
background 0.25 do
Net::HTTP.new('127.0.0.1', 9091).start do |http|
resp = http.request(Net::HTTP::Post.new("/widgets"))
if resp.code.to_i != 200
puts "[POST - #{resp.code}] #{resp.body}"
end
end
end
# Fetch widgets
background 0.05 do
Net::HTTP.new('127.0.0.1', 9091).start do |http|
resp = http.request(Net::HTTP::Get.new("/widgets"))
if resp.code.to_i != 200
puts "[GET - #{resp.code}] #{resp.body}"
end
end
end
# Reload
background 4 do
redeploy "train_app"
end
end
THREADS.each { |t| t.join }
SERVER.stop