Class: Restate::Service

Inherits:
Object
  • Object
show all
Extended by:
ServiceDSL
Defined in:
lib/restate/service.rb,
sig/restate.rbs

Overview

A stateless Restate service.

Examples:

class Greeter < Restate::Service
  handler def greet(ctx, name)
    ctx.run_sync('build-greeting') { "Hello, #{name}!" }
  end
end

Class Method Summary collapse

Methods included from ServiceDSL

abort_timeout, description, enable_lazy_state, handlers, idempotency_retention, inactivity_timeout, ingress_private, inherited, invocation_retry_policy, journal_retention, lazy_state?, metadata, service_name, service_tag, state, svc_abort_timeout, svc_idempotency_retention, svc_inactivity_timeout, svc_ingress_private, svc_invocation_retry_policy, svc_journal_retention

Class Method Details

._service_kindObject



60
61
62
# File 'lib/restate/service.rb', line 60

def self._service_kind
  'service'
end

.call(scope: nil, limit_key: nil) ⇒ ServiceCallProxy

Returns a call proxy for fluent durable calls to this service.

Examples:

Greeter.call.greet("World").await
Greeter.call(scope: "tenant1", limit_key: "tenant1/user42").greet("World").await

Parameters:

  • scope (String, nil) (defaults to: nil)

    optional scope to route the call within (see Restate.scope)

  • limit_key (String, nil) (defaults to: nil)

    optional concurrency limit key within the scope

Returns:

  • (ServiceCallProxy)


41
42
43
# File 'lib/restate/service.rb', line 41

def self.call(scope: nil, limit_key: nil)
  ServiceCallProxy.new(self, call_method: :service_call, scope: scope, limit_key: limit_key)
end

.handler(method_name = nil, **opts) ⇒ Symbol

Register a handler method on this service. Use as: handler def my_method(ctx, arg) or handler :my_method, input: String

Parameters:

  • method_name (Symbol) (defaults to: nil)

    name of the method to register

  • opts (Hash)

    handler options (+input:+, output:, accept:, content_type:)

Returns:

  • (Symbol)

    the method name



22
23
24
25
26
27
28
29
30
# File 'lib/restate/service.rb', line 22

def self.handler(method_name = nil, **opts)
  if method_name.is_a?(String)
    raise ArgumentError,
          "handler expects a Symbol (use `handler def #{method_name}(...)` or `handler :#{method_name}`)"
  end
  return method_name unless method_name.is_a?(Symbol)

  _register_handler(method_name, kind: nil, **opts)
end

.send!(delay: nil, scope: nil, limit_key: nil) ⇒ ServiceSendProxy

Returns a send proxy for fluent fire-and-forget sends to this service.

Examples:

Greeter.send!.greet("World")
Greeter.send!(delay: 60).greet("World")
Greeter.send!(scope: "tenant1", limit_key: "tenant1/user42").greet("World")

Parameters:

  • delay (Numeric, nil) (defaults to: nil)

    optional delay in seconds

  • scope (String, nil) (defaults to: nil)

    optional scope to route the send within (see Restate.scope)

  • limit_key (String, nil) (defaults to: nil)

    optional concurrency limit key within the scope

Returns:

  • (ServiceSendProxy)


56
57
58
# File 'lib/restate/service.rb', line 56

def self.send!(delay: nil, scope: nil, limit_key: nil)
  ServiceSendProxy.new(self, send_method: :service_send, delay: delay, scope: scope, limit_key: limit_key)
end