Class: Restate::Workflow

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

Overview

A durable workflow with a main entry point and shared handlers.

Examples:

class Signup < Restate::Workflow
  main def run(ctx, email)
    # workflow logic
  end

  handler def status(ctx)
    ctx.get("status")
  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



85
86
87
# File 'lib/restate/workflow.rb', line 85

def self._service_kind
  'workflow'
end

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

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

Examples:

UserSignup.call("user42").run("user@example.com").await
UserSignup.call("user42", scope: "tenant1", limit_key: "tenant1/user42").run(email).await

Parameters:

  • key (String)

    the workflow key

  • 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)


61
62
63
# File 'lib/restate/workflow.rb', line 61

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

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

Register a shared handler on this workflow.

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



41
42
43
44
45
46
47
48
49
# File 'lib/restate/workflow.rb', line 41

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: 'shared', **opts)
end

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

Register the main workflow entry point. Use as: main def run(ctx, arg) or main :run, 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



26
27
28
29
30
31
32
33
34
# File 'lib/restate/workflow.rb', line 26

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

  _register_handler(method_name, kind: 'workflow', **opts)
end

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

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

Examples:

UserSignup.send!("user42").run("user@example.com")
UserSignup.send!("user42", delay: 60).run("user@example.com")
UserSignup.send!("user42", scope: "tenant1", limit_key: "tenant1/user42").run(email)

Parameters:

  • key (String)

    the workflow key

  • 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)


77
78
79
80
81
82
83
# File 'lib/restate/workflow.rb', line 77

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