Class: Restate::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/restate/server.rb

Overview

Rack-compatible application that handles Restate protocol requests. Designed to work with Falcon for HTTP/2 bidirectional streaming.

Routes:

GET  /discover                     → service manifest
GET  /health                       → health check
POST /invoke/:service/:handler     → handler invocation

Defined Under Namespace

Classes: StreamingBody

Constant Summary collapse

SDK_VERSION =
Internal::SDK_VERSION
X_RESTATE_SERVER =
"restate-sdk-ruby/#{SDK_VERSION}".freeze
LOGGER =
Logger.new($stdout, progname: 'Restate::Server')

Instance Method Summary collapse

Constructor Details

#initialize(endpoint) ⇒ Server

Returns a new instance of Server.



22
23
24
25
# File 'lib/restate/server.rb', line 22

def initialize(endpoint)
  @endpoint = endpoint
  @identity_verifier = Internal::IdentityVerifier.new(endpoint.identity_keys)
end

Instance Method Details

#call(env) ⇒ Object

Rack interface



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/restate/server.rb', line 28

def call(env)
  path = env['PATH_INFO'] || '/'
  parsed = parse_path(path)

  case parsed[:type]
  when :health
    health_response
  when :discover
    handle_discover(env)
  when :invocation
    handle_invocation(env, parsed[:service], parsed[:handler])
  else
    not_found_response
  end
rescue StandardError => e
  LOGGER.error("Exception in Restate server: #{e.inspect}")
  LOGGER.error(e.backtrace&.join("\n")) if e.backtrace
  error_response(500, 'Internal server error')
end