simple_health 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2e979b4e3d4dbf2f9ecb60834482999bc793969bbeb7365a4c5707f3e98936ca
4
+ data.tar.gz: e02be03ac632436bfe0fd75a9e964a19cdd4b12fff4ec927af4e2ea4047ff405
5
+ SHA512:
6
+ metadata.gz: e221c8100578ed5d0ec6e5b5598a2f0393d1e238c8f04ecd5a329a2492060dcc359fb294f08a9f5d221ae46ca1bd7afee211eab95287926407c06156e61c3656
7
+ data.tar.gz: 7a421a813e975a8dbab89141e2e81fa9048a5312e0878e3485740d8140792ce79471c186b478c92fc96d3fdbd23c0e280e4533c6aeba6d7f5d75923a3608e7bb
@@ -0,0 +1,22 @@
1
+ # lib/simple_health/checker.rb
2
+ module SimpleHealth
3
+ class Checker
4
+ def self.check_db
5
+ # Verifica se il database è connesso (esempio per ActiveRecord)
6
+ return false unless defined?(ActiveRecord)
7
+ ActiveRecord::Base.connection.active?
8
+ rescue
9
+ false
10
+ end
11
+
12
+ def self.status_report
13
+ {
14
+ status: "ok",
15
+ timestamp: Time.now.to_i,
16
+ services: {
17
+ database: check_db ? "connected" : "disconnected"
18
+ }
19
+ }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ # lib/simple_health.rb
2
+ require "json"
3
+ require_relative "simple_health/checker"
4
+
5
+ module SimpleHealth
6
+ class Middleware
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ if env['PATH_INFO'] == '/health'
13
+ report = Checker.status_report
14
+ status = report[:services][:database] == "connected" ? 200 : 503
15
+
16
+ # Questo array di 3 elementi è la "risposta"
17
+ [
18
+ status, # 1. Lo stato (200 o 503)
19
+ { 'content-type' => 'application/json' }, # 2. Gli header (il tipo di file)
20
+ [report.to_json] # 3. Il corpo (il contenuto JSON vero e proprio)
21
+ ]
22
+ else
23
+ @app.call(env)
24
+ end
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_health
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Il Tuo Nome
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description: Fornisce un endpoint semplice per verificare la salute dei servizi collegati.
28
+ email:
29
+ - tua@email.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/simple_health.rb
35
+ - lib/simple_health/checker.rb
36
+ homepage: https://github.com/tuo-username/simple_health
37
+ licenses:
38
+ - MIT
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.0.3.1
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Monitoraggio dello stato dell'app (DB, Redis, Memoria).
59
+ test_files: []