Class: Restate::Server::ScopedContext

Inherits:
Object
  • Object
show all
Defined in:
lib/restate/server/context.rb,
sig/restate.rbs

Overview

A context for making RPC calls within a specific scope.

NOTE: This API is in preview and is not enabled by default. See Context#scope for how to enable it and for the full semantics.

Returned by ctx.scope(scope): calls and sends made through this context carry the captured scope, and each method additionally accepts an optional limit_key.

The limit key enforces hierarchical concurrency limits on invocations sharing the same scope. It can have one or two levels separated by / (e.g. "tenant1" or "tenant1/user42"). Each level must consist only of [a-zA-Z0-9_.-] characters, 1 <= length <= 36.

The limit key is not part of the request identity: two calls to the same target with the same scope and object key but different limit keys refer to the same resource instance. The limit key only affects concurrency limits.

Instance Method Summary collapse

Constructor Details

#initialize(ctx, scope) ⇒ ScopedContext

Returns a new instance of ScopedContext.

Parameters:

  • ctx (Object)
  • scope (String)


806
807
808
809
# File 'lib/restate/server/context.rb', line 806

def initialize(ctx, scope)
  @ctx = ctx
  @scope = scope
end

Instance Method Details

#object_call(service, handler, key, arg, limit_key: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET, output_serde: NOT_SET) ⇒ DurableCallFuture

Durably calls a handler on a Restate virtual object, within this scope.

Parameters:

  • service (Object)
  • handler (String, Symbol)
  • key (String)
  • arg (Object)
  • limit_key: (String, nil) (defaults to: nil)
  • idempotency_key: (String, nil) (defaults to: nil)
  • headers: (Hash[String, String], nil) (defaults to: nil)
  • input_serde: (Object) (defaults to: NOT_SET)
  • output_serde: (Object) (defaults to: NOT_SET)

Returns:



833
834
835
836
837
838
839
840
841
# File 'lib/restate/server/context.rb', line 833

def object_call(service, handler, key, arg, limit_key: nil, idempotency_key: nil,
                headers: nil, input_serde: NOT_SET, output_serde: NOT_SET)
  @ctx.object_call(
    service, handler, key, arg,
    idempotency_key: idempotency_key, headers: headers,
    input_serde: input_serde, output_serde: output_serde,
    scope: @scope, limit_key: limit_key
  )
end

#object_send(service, handler, key, arg, delay: nil, limit_key: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET) ⇒ SendHandle

Fire-and-forget send to a Restate virtual object handler, within this scope.

Parameters:

  • service (Object)
  • handler (String, Symbol)
  • key (String)
  • arg (Object)
  • delay: (Numeric, nil) (defaults to: nil)
  • limit_key: (String, nil) (defaults to: nil)
  • idempotency_key: (String, nil) (defaults to: nil)
  • headers: (Hash[String, String], nil) (defaults to: nil)
  • input_serde: (Object) (defaults to: NOT_SET)

Returns:



844
845
846
847
848
849
850
851
# File 'lib/restate/server/context.rb', line 844

def object_send(service, handler, key, arg, delay: nil, limit_key: nil,
                idempotency_key: nil, headers: nil, input_serde: NOT_SET)
  @ctx.object_send(
    service, handler, key, arg,
    delay: delay, idempotency_key: idempotency_key, headers: headers,
    input_serde: input_serde, scope: @scope, limit_key: limit_key
  )
end

#service_call(service, handler, arg, key: nil, limit_key: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET, output_serde: NOT_SET) ⇒ DurableCallFuture

Durably calls a handler on a Restate service, within this scope.

Parameters:

  • service (Object)
  • handler (String, Symbol)
  • arg (Object)
  • key: (String, nil) (defaults to: nil)
  • limit_key: (String, nil) (defaults to: nil)
  • idempotency_key: (String, nil) (defaults to: nil)
  • headers: (Hash[String, String], nil) (defaults to: nil)
  • input_serde: (Object) (defaults to: NOT_SET)
  • output_serde: (Object) (defaults to: NOT_SET)

Returns:



812
813
814
815
816
817
818
819
820
# File 'lib/restate/server/context.rb', line 812

def service_call(service, handler, arg, key: nil, limit_key: nil, idempotency_key: nil,
                 headers: nil, input_serde: NOT_SET, output_serde: NOT_SET)
  @ctx.service_call(
    service, handler, arg,
    key: key, idempotency_key: idempotency_key, headers: headers,
    input_serde: input_serde, output_serde: output_serde,
    scope: @scope, limit_key: limit_key
  )
end

#service_send(service, handler, arg, key: nil, delay: nil, limit_key: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET) ⇒ SendHandle

Fire-and-forget send to a Restate service handler, within this scope.

Parameters:

  • service (Object)
  • handler (String, Symbol)
  • arg (Object)
  • key: (String, nil) (defaults to: nil)
  • delay: (Numeric, nil) (defaults to: nil)
  • limit_key: (String, nil) (defaults to: nil)
  • idempotency_key: (String, nil) (defaults to: nil)
  • headers: (Hash[String, String], nil) (defaults to: nil)
  • input_serde: (Object) (defaults to: NOT_SET)

Returns:



823
824
825
826
827
828
829
830
# File 'lib/restate/server/context.rb', line 823

def service_send(service, handler, arg, key: nil, delay: nil, limit_key: nil,
                 idempotency_key: nil, headers: nil, input_serde: NOT_SET)
  @ctx.service_send(
    service, handler, arg,
    key: key, delay: delay, idempotency_key: idempotency_key, headers: headers,
    input_serde: input_serde, scope: @scope, limit_key: limit_key
  )
end

#workflow_call(service, handler, key, arg, limit_key: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET, output_serde: NOT_SET) ⇒ DurableCallFuture

Durably calls a handler on a Restate workflow, within this scope.

Parameters:

  • service (Object)
  • handler (String, Symbol)
  • key (String)
  • arg (Object)
  • limit_key: (String, nil) (defaults to: nil)
  • idempotency_key: (String, nil) (defaults to: nil)
  • headers: (Hash[String, String], nil) (defaults to: nil)
  • input_serde: (Object) (defaults to: NOT_SET)
  • output_serde: (Object) (defaults to: NOT_SET)

Returns:



854
855
856
857
858
859
860
861
862
# File 'lib/restate/server/context.rb', line 854

def workflow_call(service, handler, key, arg, limit_key: nil, idempotency_key: nil,
                  headers: nil, input_serde: NOT_SET, output_serde: NOT_SET)
  @ctx.workflow_call(
    service, handler, key, arg,
    idempotency_key: idempotency_key, headers: headers,
    input_serde: input_serde, output_serde: output_serde,
    scope: @scope, limit_key: limit_key
  )
end

#workflow_send(service, handler, key, arg, delay: nil, limit_key: nil, idempotency_key: nil, headers: nil, input_serde: NOT_SET) ⇒ SendHandle

Fire-and-forget send to a Restate workflow handler, within this scope.

Parameters:

  • service (Object)
  • handler (String, Symbol)
  • key (String)
  • arg (Object)
  • delay: (Numeric, nil) (defaults to: nil)
  • limit_key: (String, nil) (defaults to: nil)
  • idempotency_key: (String, nil) (defaults to: nil)
  • headers: (Hash[String, String], nil) (defaults to: nil)
  • input_serde: (Object) (defaults to: NOT_SET)

Returns:



865
866
867
868
869
870
871
872
# File 'lib/restate/server/context.rb', line 865

def workflow_send(service, handler, key, arg, delay: nil, limit_key: nil,
                  idempotency_key: nil, headers: nil, input_serde: NOT_SET)
  @ctx.workflow_send(
    service, handler, key, arg,
    delay: delay, idempotency_key: idempotency_key, headers: headers,
    input_serde: input_serde, scope: @scope, limit_key: limit_key
  )
end