|
1 | | -# #!/usr/bin/env ruby |
2 | | -# # frozen_string_literal: true |
3 | | - |
4 | | -# require 'grpc' |
5 | | - |
6 | | -# # ===================================================== |
7 | | -# # 1. Rails 환경 로드 + gRPC 폴더 autoload 제외 |
8 | | -# # ===================================================== |
9 | | -# require_relative '../config/environment' |
10 | | -# Rails.autoloaders.main.ignore(Rails.root.join('app/grpc')) |
11 | | - |
12 | | -# # ===================================================== |
13 | | -# # 2. Ruby가 gRPC 파일들을 찾을 수 있도록 경로 추가 |
14 | | -# # ===================================================== |
15 | | -# $LOAD_PATH.unshift(File.expand_path('../app/grpc', __dir__)) |
16 | | -# $LOAD_PATH.unshift(File.expand_path('../app', __dir__)) |
17 | | - |
18 | | -# # ===================================================== |
19 | | -# # 3. Proto 파일 로드 |
20 | | -# # ===================================================== |
21 | | -# require 'room/room_pb' |
22 | | -# require 'room/service_pb' |
23 | | -# require 'room/service_services_pb' |
24 | | - |
25 | | -# require 'reservation/reservation_pb' |
26 | | -# require 'reservation/service_pb' |
27 | | -# require 'reservation/service_services_pb' |
28 | | - |
29 | | -# require 'room_operating_hour/room_operating_hour_pb' |
30 | | -# require 'room_operating_hour/service_pb' |
31 | | -# require 'room_operating_hour/service_services_pb' |
32 | | - |
33 | | -# require 'room_exception/room_exception_pb' |
34 | | -# require 'room_exception/service_pb' |
35 | | -# require 'room_exception/service_services_pb' |
36 | | - |
37 | | -# require 'healthcheck/healthcheck_pb' |
38 | | -# require 'healthcheck/healthcheck_services_pb' |
39 | | - |
40 | | -# # ===================================================== |
41 | | -# # 4. 서비스 핸들러 로드 |
42 | | -# # ===================================================== |
43 | | -# require_relative 'service/room_service' |
44 | | -# require_relative 'service/reservation_service' |
45 | | -# require_relative 'service/room_operating_hour_service' |
46 | | -# require_relative 'service/room_exception_service' |
47 | | -# require_relative 'service/healthcheck_service' |
48 | | - |
49 | | -# # ===================================================== |
50 | | -# # 5. gRPC 서버 실행 |
51 | | -# # ===================================================== |
52 | | -# module Bannote |
53 | | -# module Studyroomservice |
54 | | -# module V1 |
55 | | -# def self.start |
56 | | -# # Rails가 완전히 로드된 이후에 Interceptor 불러오기 |
57 | | -# require_relative '../app/interceptors/auth_interceptor' |
58 | | - |
59 | | -# # 환경 변수 기반 gRPC 포트 (없으면 기본값 50053) |
60 | | -# grpc_port = ENV.fetch('GRPC_PORT', '50053') |
61 | | - |
62 | | -# puts "[gRPC] Starting StudyroomService on port #{grpc_port}..." |
63 | | -# puts "[gRPC] Environment: #{ENV.fetch('RAILS_ENV', 'development')}" |
64 | | -# puts "[gRPC] Using database host: #{ENV.fetch('DB_HOST', '(not set)')}" |
65 | | - |
66 | | -# # 서버 초기화 |
67 | | -# server = GRPC::RpcServer.new( |
68 | | -# interceptors: [AuthInterceptor.new] |
69 | | -# ) |
70 | | - |
71 | | -# # 포트 바인딩 |
72 | | -# server.add_http2_port("0.0.0.0:#{grpc_port}", :this_port_is_insecure) |
73 | | - |
74 | | -# # 서비스 핸들러 등록 (네임스페이스 주의) |
75 | | -# server.handle(Bannote::Studyroomservice::Room::V1::RoomServiceHandler.new) |
76 | | -# server.handle(Bannote::Studyroomservice::Reservation::V1::ReservationServiceHandler.new) |
77 | | -# server.handle(Bannote::Studyroomservice::Roomoperatinghour::V1::RoomOperatingHourServiceHandler.new) |
78 | | -# server.handle(Bannote::Studyroomservice::Roomexception::V1::RoomExceptionServiceHandler.new) |
79 | | -# server.handle(Grpc::Health::V1::HealthServer) |
80 | | - |
81 | | -# puts "[gRPC] Successfully bound to 0.0.0.0:#{grpc_port}" |
82 | | -# puts "[gRPC] Waiting for incoming requests..." |
83 | | - |
84 | | -# # ===================================================== |
85 | | -# # 종료 시그널 안전 처리 (Thread-safe) |
86 | | -# # ===================================================== |
87 | | -# stop_requested = false |
88 | | -# trap('INT') { stop_requested = true } |
89 | | -# trap('TERM') { stop_requested = true } |
90 | | - |
91 | | -# # gRPC 서버 실행을 별도 스레드에서 수행 |
92 | | -# server_thread = Thread.new do |
93 | | -# begin |
94 | | -# server.run_till_terminated |
95 | | -# rescue => e |
96 | | -# STDERR.puts "[gRPC] Server thread error: #{e.class} - #{e.message}" |
97 | | -# STDERR.puts e.backtrace.join("\n") |
98 | | -# end |
99 | | -# end |
100 | | - |
101 | | -# # 종료 감시 루프 |
102 | | -# until stop_requested |
103 | | -# sleep 1 |
104 | | -# end |
105 | | - |
106 | | -# puts "[gRPC] Stopping server gracefully..." |
107 | | -# server.stop |
108 | | -# server_thread.join |
109 | | -# puts "[gRPC] Server stopped cleanly." |
110 | | - |
111 | | -# rescue => e |
112 | | -# STDERR.puts "[gRPC] Fatal error: #{e.class} - #{e.message}" |
113 | | -# STDERR.puts e.backtrace.join("\n") |
114 | | -# exit 1 |
115 | | -# end |
116 | | -# end |
117 | | -# end |
118 | | -# end |
119 | | - |
120 | | -# # ===================================================== |
121 | | -# # 6. 서버 시작 |
122 | | -# # ===================================================== |
123 | | -# Bannote::Studyroomservice::V1.start |
124 | | - |
125 | | - |
126 | | -#!/usr/bin/env ruby |
127 | | -# frozen_string_literal: true |
128 | | - |
129 | 1 | #!/usr/bin/env ruby |
130 | 2 | # frozen_string_literal: true |
131 | 3 |
|
|
0 commit comments