koa-utils 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/koa-utils/health-check.rb +14 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44d367611792021c6ccb24e9481033a15c957fa3
|
4
|
+
data.tar.gz: b098b35bf9aadf96449c0f80c109e236865f7d98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0224a865f0e7a23c517f4dea81ccb6c9e9a6e66b640164a15a842b044d2024dfd4bf42242e3b2acb643c456b349d908aab132be7413fe9b1f88c3c3dc1c7265b
|
7
|
+
data.tar.gz: afa0778b449961f71b50007278199b99e637ed374cb2ce64b30108f6f3dda047213a049b3d58e073344f8aa4d145b545e25dc31c8fe88e3f3f66d551a86eb665
|
@@ -1,19 +1,27 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'timeout'
|
3
3
|
|
4
|
-
if !defined?(ActiveRecord)
|
5
|
-
raise("KOAUtils::HealthCheck expects ActiveRecord to be defined.")
|
6
|
-
end
|
7
|
-
|
8
4
|
class KOAUtils::HealthCheck
|
9
5
|
def self.call(env)
|
10
6
|
begin
|
11
7
|
Timeout::timeout(2) do
|
12
|
-
|
8
|
+
db_check
|
13
9
|
end
|
14
10
|
rescue => e
|
15
|
-
return [500, {"Content-Type" => "text/json"},
|
11
|
+
return [500, {"Content-Type" => "text/json"},
|
12
|
+
[JSON.dump({error: e.message})]]
|
16
13
|
end
|
17
14
|
[200, {"Content-Type" => "text/json"}, [JSON.dump({info: Time.now})]]
|
18
15
|
end
|
16
|
+
|
17
|
+
def self.db_check
|
18
|
+
query = "select * from information_schema.tables"
|
19
|
+
if defined?(ActiveRecord)
|
20
|
+
ActiveRecord::Base.connection.execute(query)
|
21
|
+
elsif defined?(Sequel)
|
22
|
+
c = Sequel.connect(ENV["DATABASE_URL"])
|
23
|
+
c.exec(query)
|
24
|
+
c.disconnect
|
25
|
+
end
|
26
|
+
end
|
19
27
|
end
|