Class: Restate::Workflow

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

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



75
76
77
# File 'lib/restate/workflow.rb', line 75

def self._service_kind
  'workflow'
end

.call(key) ⇒ ServiceCallProxy

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

Examples:

UserSignup.call("user42").run("user@example.com").await

Parameters:

  • key (String)

    the workflow key

Returns:

  • (ServiceCallProxy)


58
59
60
# File 'lib/restate/workflow.rb', line 58

def self.call(key)
  ServiceCallProxy.new(self, key: key, call_method: :workflow_call)
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) ⇒ 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")

Parameters:

  • key (String)

    the workflow key

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

    optional delay in seconds

Returns:

  • (ServiceSendProxy)


71
72
73
# File 'lib/restate/workflow.rb', line 71

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