Class: Fluent::Plugin::GcloudPubSubInput::RPCServlet
- Inherits:
-
WEBrick::HTTPServlet::AbstractServlet
- Object
- WEBrick::HTTPServlet::AbstractServlet
- Fluent::Plugin::GcloudPubSubInput::RPCServlet
- Defined in:
- lib/fluent/plugin/in_gcloud_pubsub.rb
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
-
#do_GET(req, res) ⇒ Object
rubocop:disable Naming/MethodName.
-
#initialize(server, plugin) ⇒ RPCServlet
constructor
A new instance of RPCServlet.
- #process(req, _res) ⇒ Object
-
#render_json(code, obj) ⇒ Object
rubocop:enable Naming/MethodName.
Constructor Details
#initialize(server, plugin) ⇒ RPCServlet
Returns a new instance of RPCServlet.
66 67 68 69 |
# File 'lib/fluent/plugin/in_gcloud_pubsub.rb', line 66 def initialize(server, plugin) super @plugin = plugin end |
Instance Method Details
#do_GET(req, res) ⇒ Object
rubocop:disable Naming/MethodName
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/fluent/plugin/in_gcloud_pubsub.rb', line 72 def do_GET(req, res) begin code, header, body = process(req, res) rescue StandardError code, header, body = render_json(500, { "ok" => false, "message" => "Internal Server Error", "error" => $ERROR_INFO.to_s, "backtrace" => $ERROR_INFO.backtrace, }) end res.status = code header.each_pair do |k, v| res[k] = v end res.body = body end |
#process(req, _res) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/fluent/plugin/in_gcloud_pubsub.rb', line 96 def process(req, _res) ret = { "ok" => true } case req.path_info when "/stop" @plugin.stop_pull when "/start" @plugin.start_pull when "/status" ret["status"] = @plugin.status_of_pull else raise Error, "Invalid path_info: #{req.path_info}" end render_json(200, ret) end |
#render_json(code, obj) ⇒ Object
rubocop:enable Naming/MethodName
92 93 94 |
# File 'lib/fluent/plugin/in_gcloud_pubsub.rb', line 92 def render_json(code, obj) [code, { "Content-Type" => "application/json" }, obj.to_json] end |