Skip to content

Commit 074d83b

Browse files
committed
remove hanami-router for rack 3.0 compatability
1 parent 5687f62 commit 074d83b

File tree

6 files changed

+34
-35
lines changed

6 files changed

+34
-35
lines changed

bin/liteboard

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# frozen_string_literal: true
33

44
require 'optparse'
5+
require 'rackup'
56
require_relative '../lib/litestack/liteboard/liteboard'
67
DEFAULTS = {
78
config_path: Litemetric::DEFAULT_OPTIONS[:config_path],
@@ -15,7 +16,7 @@ options = {
1516
Port: 9292,
1617
Host: 'localhost',
1718
environment: 'production',
18-
pid: 'tmp/pids/liteboard.pid',
19+
pid: './liteboard.pid',
1920
quiet: false
2021
}
2122

@@ -79,4 +80,4 @@ options[:app] = Liteboard.app
7980
require_relative '../lib/litestack'
8081
puts "Starting Liteboard version #{Litestack::VERSION}"
8182

82-
Rack::Server.start(options)
83+
Rackup::Server.start(options)

lib/litestack/liteboard/liteboard.rb

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

3-
require "hanami/router"
3+
require "rack"
44
require "tilt"
55
require "erubi"
66

@@ -11,37 +11,32 @@ class Liteboard
1111
@@resolutions = {"minute" => [300, 12], "hour" => [3600, 24], "day" => [3600 * 24, 7], "week" => [3600 * 24 * 7, 53], "year" => [3600 * 24 * 365, 100]}
1212
@@res_mapping = {"hour" => "minute", "day" => "hour", "week" => "day", "year" => "week"}
1313
@@templates = {}
14-
@@app = Hanami::Router.new do
15-
get "/", to: ->(env) do
14+
@@app = proc do |env|
15+
case path = env["PATH_INFO"]
16+
when "/"
1617
Liteboard.new(env).call(:index)
17-
end
18-
19-
get "/topics/Litejob", to: ->(env) do
18+
when "/topics/Litejob"
2019
Liteboard.new(env).call(:litejob)
21-
end
22-
23-
get "/topics/Litecache", to: ->(env) do
20+
when "/topics/Litecache"
2421
Liteboard.new(env).call(:litecache)
25-
end
26-
27-
get "/topics/Litedb", to: ->(env) do
22+
when "/topics/Litedb"
2823
Liteboard.new(env).call(:litedb)
29-
end
30-
31-
get "/topics/Litecable", to: ->(env) do
24+
when "/topics/Litecable"
3225
Liteboard.new(env).call(:litecable)
3326
end
27+
3428
end
3529

3630
def initialize(env)
3731
@env = env
38-
@params = @env["router.params"]
32+
@req = Rack::Request.new(@env)
33+
@params = @req.params
3934
@running = true
4035
@lm = Litemetric.instance
4136
end
4237

4338
def params(key)
44-
URI.decode_uri_component(@params[key].to_s)
39+
URI.decode_uri_component(@params[key.to_s].to_s)
4540
end
4641

4742
def call(method)
@@ -227,9 +222,9 @@ def litejob
227222
@topic = "Litejob"
228223
@events = @lm.events_summaries(@topic, @resolution, @order, @dir, @search, @step * @count)
229224
@events.each do |event|
230-
data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event["name"])
225+
data_points = @lm.event_data_points(@step, @count, @resolution, @topic, event[:name])
231226
event["counts"] = data_points.collect { |r| [r["rtime"], r["rcount"] || 0] }
232-
event["values"] = data_points.collect { |r| [r["rtime"], r["rtotal"] || 0] }
227+
event["values"] = data_points.collect { |r| [r["rtime"], (r["rtotal"] || 0.0)] }
233228
end
234229
@snapshot = read_snapshot(@topic)
235230
@size = begin
@@ -391,6 +386,7 @@ def round(float)
391386
end
392387

393388
def format(float)
389+
float = float.round(3)
394390
string = float.to_s
395391
whole, decimal = string.split(".")
396392
whole = whole.chars.reverse.each_slice(3).map(&:join).join(",").reverse

lib/litestack/litejobqueue.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,16 @@ def stop
141141

142142
def exit_callback
143143
@running = false # stop all workers
144-
return unless @jobs_in_flight > 0
145-
puts "--- Litejob detected an exit, cleaning up"
146-
index = 0
147-
while @jobs_in_flight > 0 && index < 30 # 3 seconds grace period for jobs to finish
148-
puts "--- Waiting for #{@jobs_in_flight} jobs to finish"
149-
sleep 0.1
150-
index += 1
144+
if @jobs_in_flight > 0
145+
puts "--- Litejob detected an exit, cleaning up"
146+
index = 0
147+
while @jobs_in_flight > 0 && index < 30 # 3 seconds grace period for jobs to finish
148+
puts "--- Waiting for #{@jobs_in_flight} jobs to finish"
149+
sleep 0.1
150+
index += 1
151+
end
152+
puts " --- Exiting with #{@jobs_in_flight} jobs in flight"
151153
end
152-
puts " --- Exiting with #{@jobs_in_flight} jobs in flight"
153154
end
154155

155156
def setup

lib/litestack/litemetric.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,11 @@ def run_stmt_hash(stmt, *args)
148148
end
149149

150150
def exit_callback
151-
return unless @collector.count > 0
152-
warn "--- Litemetric detected an exit, flushing metrics"
153151
@running = false
154-
@collector.flush
152+
if @collector.count > 0
153+
warn "--- Litemetric detected an exit, flushing metrics"
154+
@collector.flush
155+
end
155156
end
156157

157158
def setup
@@ -203,8 +204,8 @@ def collect_metrics
203204
def create_snapshotter
204205
Litescheduler.spawn do
205206
while @running
206-
sleep @litemetric.options[:snapshot_interval]
207207
capture_snapshot
208+
sleep @litemetric.options[:snapshot_interval]
208209
end
209210
end
210211
end

lib/litestack/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Litestack
4-
VERSION = "0.4.3"
4+
VERSION = "0.4.4"
55
end

litestack.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
3333
spec.add_dependency "sqlite3"
3434
spec.add_dependency "oj"
3535
spec.add_dependency "rack"
36-
spec.add_dependency "hanami-router", "~> 2.0"
36+
spec.add_dependency "rackup"
3737
spec.add_dependency "tilt"
3838
spec.add_dependency "erubi"
3939

0 commit comments

Comments
 (0)