pliny 0.13.1 → 0.14.0
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/pliny.rb +0 -1
- data/lib/pliny/tasks/db.rake +3 -1
- data/lib/pliny/version.rb +1 -1
- data/lib/template/Gemfile +2 -1
- data/lib/template/config/initializers/database.rb +1 -1
- data/lib/template/db/seeds.rb +2 -3
- data/lib/template/lib/endpoints/health.rb +29 -0
- data/lib/template/lib/routes.rb +1 -0
- data/lib/template/spec/endpoints/health_spec.rb +55 -0
- metadata +5 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13b0d6020bd07cb9d55632ccc06ee95bf4114fbd
|
4
|
+
data.tar.gz: 40fd92d34a2c2c75e124a5893454335b14ffdd1b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c240442d80aea58d7327885bb1c573152ed5d831420da2b6f0e07e0c7838101c8d5aeeed1e44a8ebdb344fe36dfba0b8679ccd7e1c4b82b773c1af7685dac509
|
7
|
+
data.tar.gz: dfc01de138d783f33cc28b640382155311e363e4137e4791fb9e15a07b93df2a72350d5ec983b81face3c9fb5d8912fe116d6ce4a1971c9c29d51a7afc885000
|
data/lib/pliny.rb
CHANGED
data/lib/pliny/tasks/db.rake
CHANGED
@@ -34,7 +34,9 @@ begin
|
|
34
34
|
task :seed do
|
35
35
|
if File.exist?('./db/seeds.rb')
|
36
36
|
database_urls.each do |database_url|
|
37
|
-
|
37
|
+
# make a DB instance available to the seeds file
|
38
|
+
self.class.send(:remove_const, 'DB') if self.class.const_defined?('DB')
|
39
|
+
self.class.const_set('DB', Sequel.connect(database_url))
|
38
40
|
load 'db/seeds.rb'
|
39
41
|
end
|
40
42
|
disconnect
|
data/lib/pliny/version.rb
CHANGED
data/lib/template/Gemfile
CHANGED
@@ -4,10 +4,11 @@ ruby "2.2.3"
|
|
4
4
|
gem "multi_json"
|
5
5
|
gem "oj"
|
6
6
|
gem "pg"
|
7
|
-
gem "pliny", "~> 0.
|
7
|
+
gem "pliny", "~> 0.14"
|
8
8
|
gem "pry"
|
9
9
|
gem "puma", "~> 2.10"
|
10
10
|
gem "rack-ssl"
|
11
|
+
gem "rack-timeout", "~> 0.3"
|
11
12
|
gem "rake"
|
12
13
|
gem "rollbar", require: "rollbar/middleware/sinatra"
|
13
14
|
gem "sequel", "~> 4.16"
|
data/lib/template/db/seeds.rb
CHANGED
@@ -4,6 +4,5 @@
|
|
4
4
|
# db with db:setup).
|
5
5
|
#
|
6
6
|
# Seeding can occur multiple times during the execution of a single Rake task
|
7
|
-
# because
|
8
|
-
#
|
9
|
-
# `Sequel::DATABASES.last`.
|
7
|
+
# because it applies to all your app environments (eg: test and development).
|
8
|
+
# An instance of the current database connection is available as `DB`.
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Endpoints
|
2
|
+
class Health < Base
|
3
|
+
namespace '/health' do
|
4
|
+
get do
|
5
|
+
encode({})
|
6
|
+
end
|
7
|
+
|
8
|
+
get '/db' do
|
9
|
+
database?
|
10
|
+
database_available?
|
11
|
+
encode({})
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def database?
|
17
|
+
fail Pliny::Errors::NotFound if DB.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
def database_available?
|
21
|
+
fail Pliny::Errors::ServiceUnavailable unless DB.test_connection
|
22
|
+
rescue Sequel::Error => e
|
23
|
+
message = e.message.strip
|
24
|
+
Pliny.log(db: true, health: true, at: 'exception', message: message)
|
25
|
+
raise Pliny::Errors::ServiceUnavailable
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/template/lib/routes.rb
CHANGED
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe Endpoints::Health do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
def app
|
7
|
+
Endpoints::Health
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'GET /health' do
|
11
|
+
it 'returns a 200' do
|
12
|
+
get '/health'
|
13
|
+
assert_equal(200, last_response.status)
|
14
|
+
assert_equal('application/json;charset=utf-8', last_response.headers['Content-Type'])
|
15
|
+
assert_equal(2, last_response.headers['Content-Length'].to_i)
|
16
|
+
assert_equal({}, MultiJson.decode(last_response.body))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe 'GET /health/db' do
|
21
|
+
it 'raises a 404 when no database is available' do
|
22
|
+
allow(DB).to receive(:nil?).and_return(true)
|
23
|
+
|
24
|
+
assert_raises Pliny::Errors::NotFound do
|
25
|
+
get '/health/db'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'raises a 503 on Sequel exceptions' do
|
30
|
+
allow(DB).to receive(:test_connection).and_raise(Sequel::Error)
|
31
|
+
|
32
|
+
assert_raises Pliny::Errors::ServiceUnavailable do
|
33
|
+
get '/health/db'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'raises a 503 when connection testing fails' do
|
38
|
+
allow(DB).to receive(:test_connection).and_return(false)
|
39
|
+
|
40
|
+
assert_raises Pliny::Errors::ServiceUnavailable do
|
41
|
+
get '/health/db'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns a 200' do
|
46
|
+
allow(DB).to receive(:test_connection).and_return(true)
|
47
|
+
|
48
|
+
get '/health/db'
|
49
|
+
assert_equal(200, last_response.status)
|
50
|
+
assert_equal('application/json;charset=utf-8', last_response.headers['Content-Type'])
|
51
|
+
assert_equal(2, last_response.headers['Content-Length'].to_i)
|
52
|
+
assert_equal({}, MultiJson.decode(last_response.body))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pliny
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandur Leach
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-12-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -65,26 +65,6 @@ dependencies:
|
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: 0.7.0
|
68
|
-
- !ruby/object:Gem::Dependency
|
69
|
-
name: rack-timeout
|
70
|
-
requirement: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - "~>"
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '0.3'
|
75
|
-
- - ">="
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: 0.3.1
|
78
|
-
type: :runtime
|
79
|
-
prerelease: false
|
80
|
-
version_requirements: !ruby/object:Gem::Requirement
|
81
|
-
requirements:
|
82
|
-
- - "~>"
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
version: '0.3'
|
85
|
-
- - ">="
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version: 0.3.1
|
88
68
|
- !ruby/object:Gem::Dependency
|
89
69
|
name: sinatra
|
90
70
|
requirement: !ruby/object:Gem::Requirement
|
@@ -422,6 +402,7 @@ files:
|
|
422
402
|
- lib/template/db/seeds.rb
|
423
403
|
- lib/template/lib/application.rb
|
424
404
|
- lib/template/lib/endpoints/base.rb
|
405
|
+
- lib/template/lib/endpoints/health.rb
|
425
406
|
- lib/template/lib/endpoints/root.rb
|
426
407
|
- lib/template/lib/endpoints/schema.rb
|
427
408
|
- lib/template/lib/initializer.rb
|
@@ -431,6 +412,7 @@ files:
|
|
431
412
|
- lib/template/lib/tasks/spec.rake
|
432
413
|
- lib/template/schema/meta.json
|
433
414
|
- lib/template/schema/schemata/.gitkeep
|
415
|
+
- lib/template/spec/endpoints/health_spec.rb
|
434
416
|
- lib/template/spec/endpoints/schema_spec.rb
|
435
417
|
- lib/template/spec/spec_helper.rb
|
436
418
|
- lib/template/spec/spec_support/auto_define_rack_app.rb
|
@@ -482,7 +464,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
482
464
|
version: '0'
|
483
465
|
requirements: []
|
484
466
|
rubyforge_project:
|
485
|
-
rubygems_version: 2.4.
|
467
|
+
rubygems_version: 2.4.3
|
486
468
|
signing_key:
|
487
469
|
specification_version: 4
|
488
470
|
summary: Basic tooling to support API apps in Sinatra
|