Class: JetstreamBridge::Generators::HealthCheckGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/jetstream_bridge/health_check/health_check_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_routeObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/generators/jetstream_bridge/health_check/health_check_generator.rb', line 15

def add_route
  route_content = "  # JetStream Bridge health check endpoint\n  " \
                  "get '/health/jetstream', to: 'jetstream_health#show'"

  if File.exist?('config/routes.rb')
    inject_into_file 'config/routes.rb', after: /Rails\.application\.routes\.draw do\n/ do
      "#{route_content}\n"
    end
    say 'Added health check route to config/routes.rb', :green
  else
    say 'Could not find config/routes.rb - please add route manually:', :yellow
    say route_content, :yellow
  end
end

#create_controllerObject



11
12
13
# File 'lib/generators/jetstream_bridge/health_check/health_check_generator.rb', line 11

def create_controller
  template 'health_controller.rb', 'app/controllers/jetstream_health_controller.rb'
end

#show_usageObject



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
# File 'lib/generators/jetstream_bridge/health_check/health_check_generator.rb', line 30

def show_usage
  say "\n#{'=' * 70}", :green
  say 'Health Check Endpoint Created!', :green
  say '=' * 70, :green
  say "\nThe health check endpoint is now available at:"
  say '  GET /health/jetstream', :cyan
  say "\nExample response:"
  say "    {\n      \"healthy\": true,\n      \"nats_connected\": true,\n      \"connected_at\": \"2025-11-22T20:00:00Z\",\n      \"stream\": {\n        \"exists\": true,\n        \"name\": \"development-jetstream-bridge-stream\",\n        \"subjects\": [\"dev.app1.sync.app2\"],\n        \"messages\": 42\n      },\n      \"config\": {\n        \"env\": \"development\",\n        \"app_name\": \"my_app\",\n        \"destination_app\": \"other_app\"\n      },\n      \"version\": \"2.10.0\"\n    }\n  EXAMPLE\n  say \"\\nUse this endpoint for:\"\n  say '  \u2022 Kubernetes liveness/readiness probes', :white\n  say '  \u2022 Docker health checks', :white\n  say '  \u2022 Monitoring and alerting', :white\n  say '  \u2022 Load balancer health checks', :white\n  say '=' * 70, :green\nend\n", :white