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 and Elixir SDK is a framework for authoring workflows and activities using the Erlang and Elixir programming languages.

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 and 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].

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 and Elixir SDK

Topics

Resources

License

Stars

Watchers

Forks

Languages