Skip to content

andrzej-mag/temporal_sdk

Repository files navigation

Hex Version Hex Docs

Project status: work in progress - under active development. The TODO.md file can be considered as a project progress tracker.

Temporal is a distributed, scalable, durable, and highly available orchestration engine used to execute asynchronous, long-running business logic in a scalable and resilient way.

Temporal Erlang/Elixir SDK is a framework for authoring workflows and activities using the Erlang and Elixir programming languages.

The Erlang/Elixir SDK is a native Temporal SDK implemented in Erlang, with a lightweight Elixir wrapper. SDK doesn't use any NIFs or ports. SDK connects directly to Temporal Cluster(s) using built-in gRPC client. By implementing the temporal_sdk_grpc_adapter behaviour, any HTTP/2 adapter can be used for gRPC transport. The gun package is used as the default HTTP/2 adapter. Temporal gRPC API protocol buffers are compiled using an external Erlang script based on the gpb package.

Native Erlang SDK implementation leverages OTP's unique capabilities to deliver features unavailable in other SDKs, for example:

  • Flexible workflow eviction based on individual workflow execution properties and business logic, rather than a simple LRU policy used in other SDKs. This feature enables optimization of worker node infrastructure costs, especially for long-running workflows. [docs], [sample 1], [sample 2].
  • Flexible dynamic concurrency, fixed window and leaky bucket Temporal tasks rate limiters. [docs], [sample].
  • Parallel workflow executions and composable await() functions simplify the implementation of workflow business logic. [sample 1], [sample 2].
  • Ergonomic and flexible handling of activity heartbeats. [sample].
  • Temporal events are a first-class SDK feature and can be awaited using composable await() functions. [sample 1], [sample 2], [sample 3].
  • ETS tables store workflow awaitables and raw Temporal events, enabling querying of workflow event histories using ETS query semantics. [sample].
  • Mutable markers that can reset-mutate workflow execution during workflow replay, for example, in response to environmental variable changes (experimental feature). [sample].
  • OTP messages handling in workflows and activities (WIP). Feature will, for example, improve performance for workflow pseudo-signals/queries dispatched as OTP messages with fallback to regular signal/query if live workflow execution is not available in the worker nodes cluster.

Quick Start (Elixir)

Full code for the following HelloWorld example, along with other code samples, can be found in the temporal_sdk_samples repository. Please refer to the documentation Quick Start guide for an extended version of this example with Erlang code snippets.

Add temporal_sdk to your application dependencies list:

# mix.exs
  defp deps do
    [
      {:temporal_sdk, ">= 0.0.0"}
    ]
  end

Configure :cluster_1 SDK cluster with activity and workflow runtime task workers that poll for tasks from the "default" activity and workflow task queues:

# config/config.exs
config :temporal_sdk,
  clusters: [
    cluster_1: [
      activities: [[task_queue: "default"]],
      workflows: [[task_queue: "default"]]
    ]
  ]

Implement Temporal activity definition:

# lib/hello_world_activity.ex
defmodule HelloWorld.Activity do
  use TemporalSdk.Activity

  @impl true
  def execute(_context, [[string]]), do: [[String.upcase(string)]]
end

Implement Temporal workflow definition and a start/0 helper function that starts and awaits the execution of HelloWorld.Workflow workflow:

# lib/hello_world_workflow.ex
defmodule HelloWorld.Workflow do
  use TemporalSdk.Workflow

  @impl true
  def execute(_context, input) do
    a1 = start_activity(HelloWorld.Activity, [["hello"]])
    a2 = start_activity(HelloWorld.Activity, [["world"]])
    [%{result: a1_result}, %{result: a2_result}] = wait_all([a1, a2])
    IO.puts("#{a1_result} #{a2_result} #{input} \n")
  end

  def start do
    TemporalSdk.start_workflow(:cluster_1, "default", HelloWorld.Workflow, [
      :wait,
      input: [["from Temporal"]]
    ])
  end
end

Start iex -S mix and run Temporal workflow execution:

iex(1)> HelloWorld.Workflow.start()
HELLO WORLD from Temporal
...

Requirements

The basic config.exs configuration file provided above assumes an unsecured Temporal server running on localhost:7233. For development and testing purposes it is recommended to run the Temporal CLI locally:

  1. Install Temporal CLI.
  2. Start Temporal CLI dev server.

License

Temporal Erlang/Elixir SDK is distributed under the Business Source License (BSL).

For more information on the use of the BSL generally, please visit the Adopting and Developing Business Source License FAQ.

Pricing

The software monthly subscription fee is €100 (plus VAT/tax where applicable) per production application that uses this SDK as a dependency.

To subscribe or manage your subscription, please visit the [Subscription Management Link TBA].

Sponsoring

The Temporal Erlang/Elixir SDK is under active development. Financial sponsorship helps sustain work on this project. To discuss sponsorship, contact me via the links on my hex.pm profile or open a thread in GitHub Discussions.

Contributing

Contributors must agree to the Individual Contributor License Agreement. When creating your first pull request, please copy and paste the following acknowledgment as your first commit message:

I have read the Individual Contributor License Agreement (ICLA) and hereby sign the ICLA.

About

Temporal Erlang/Elixir SDK

Topics

Resources

License

Stars

15 stars

Watchers

0 watching

Forks

Contributors

Languages