Temporalex.Backend behaviour (Temporalex v0.4.0)

Copy Markdown View Source

Backend boundary for Temporal client and worker transport.

Backends own client resources, worker resources, and protocol translation. They deliver decoded core structs to Temporalex.Server, accept core completions from it, and execute public client operations for Temporalex.Client. Backend-specific transport, protobuf, native resources, and worker handles must stay behind this behaviour.

Summary

Types

client_state()

@type client_state() :: term()

worker_state()

@type worker_state() :: term()

Callbacks

cancel_workflow(client_state, workflow_id, run_id, opts)

@callback cancel_workflow(
  client_state(),
  workflow_id :: binary(),
  run_id :: binary() | nil,
  opts :: keyword()
) :: :ok | {:error, term()}

complete_activity_task(worker_state, t)

@callback complete_activity_task(
  worker_state(),
  Temporalex.Core.ActivityCompletion.t()
) :: :ok | {:error, term()}

complete_workflow_activation(worker_state, t)

@callback complete_workflow_activation(
  worker_state(),
  Temporalex.Core.Completion.t()
) :: :ok | {:error, term()}

describe_workflow(client_state, workflow_id, run_id, opts)

@callback describe_workflow(
  client_state(),
  workflow_id :: binary(),
  run_id :: binary() | nil,
  opts :: keyword()
) :: {:ok, term()} | {:error, term()}

get_workflow_result(client_state, workflow_id, run_id, opts)

@callback get_workflow_result(
  client_state(),
  workflow_id :: binary(),
  run_id :: binary() | nil,
  opts :: keyword()
) :: {:ok, term()} | {:error, term()}

query_workflow(client_state, workflow_id, run_id, query_name, args, opts)

@callback query_workflow(
  client_state(),
  workflow_id :: binary(),
  run_id :: binary() | nil,
  query_name :: binary(),
  args :: list(),
  opts :: keyword()
) :: {:ok, term()} | {:error, term()}

record_activity_heartbeat(worker_state, task_token, details)

@callback record_activity_heartbeat(
  worker_state(),
  task_token :: binary(),
  details :: term()
) :: :ok | {:error, term()}

shutdown_client(client_state)

@callback shutdown_client(client_state()) :: :ok | {:error, term()}

shutdown_worker(worker_state)

@callback shutdown_worker(worker_state()) :: :ok | {:error, term()}

signal_workflow(client_state, workflow_id, run_id, signal_name, args, opts)

@callback signal_workflow(
  client_state(),
  workflow_id :: binary(),
  run_id :: binary() | nil,
  signal_name :: binary(),
  args :: list(),
  opts :: keyword()
) :: :ok | {:error, term()}

start_client(opts, owner_pid)

@callback start_client(opts :: keyword(), owner_pid :: pid()) ::
  {:ok, client_state()} | {:error, term()}

start_worker(client_state, opts, owner_pid)

@callback start_worker(client_state(), opts :: keyword(), owner_pid :: pid()) ::
  {:ok, worker_state()} | {:error, term()}

start_workflow(client_state, workflow_type, input, opts)

@callback start_workflow(
  client_state(),
  workflow_type :: binary(),
  input :: term(),
  opts :: keyword()
) :: {:ok, map()} | {:error, term()}

terminate_workflow(client_state, workflow_id, run_id, opts)

@callback terminate_workflow(
  client_state(),
  workflow_id :: binary(),
  run_id :: binary() | nil,
  opts :: keyword()
) :: :ok | {:error, term()}

update_workflow(client_state, workflow_id, run_id, update_name, args, opts)

@callback update_workflow(
  client_state(),
  workflow_id :: binary(),
  run_id :: binary() | nil,
  update_name :: binary(),
  args :: list(),
  opts :: keyword()
) :: {:ok, term()} | {:error, term()}