Quick Start

View Source

Full code for this example can be found in the temporal_sdk_samples repository as a HelloWorld/hello_world sample.

Add temporal_sdk to your application runtime dependencies list:

Elixir

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

Erlang

%% rebar3.config
{deps, [
    temporal_sdk
]}.

%% src/hello_world.app.src
{application, hello_world, [
    {applications, [
        temporal_sdk
    ]}
]}.

Configure activity and workflow runtime task workers:

Elixir

# config/config.exs
config :temporal_sdk,
  clusters: [
    cluster_1: [
      activities: [%{:task_queue => "default"}],
      workflows: [%{:task_queue => "default"}]
    ]
  ]

See: TemporalSdk.Node, TemporalSdk.Cluster and TemporalSdk.Worker

Erlang

%% config/sys.config
[
    {temporal_sdk, [
        {clusters, [
            {cluster_1, [
                {activities, [#{task_queue => "default"}]},
                {workflows, [#{task_queue => "default"}]}
            ]}
        ]}
    ]}
].

See: :temporal_sdk_node, :temporal_sdk_cluster and :temporal_sdk_worker

Implement Temporal activity definition:

Elixir

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

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

See: TemporalSdk.Activity

Erlang

%% src/hello_world_activity.erl
-module(hello_world_activity).

-export([execute/2]).

-include_lib("temporal_sdk/include/activity.hrl").

execute(_Context, [String]) -> [string:uppercase(String)].

See: :temporal_sdk_activity

Implement Temporal workflow definition:

Elixir

# 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

See: TemporalSdk.Workflow

Erlang

%% src/hello_world_workflow.erl
-module(hello_world_workflow).

-export([execute/2, start/0]).

-include_lib("temporal_sdk/include/workflow.hrl").

execute(_Context, Input) ->
    A1 = start_activity(hello_world_activity, ["hello"]),
    A2 = start_activity(hello_world_activity, ["world"]),
    [#{result := A1Result}, #{result := A2Result}] = wait_all([A1, A2]),
    io:fwrite("~s ~s ~s~n~n", [A1Result, A2Result, Input]).

start() ->
    temporal_sdk:start_workflow(cluster_1, "default", hello_world_workflow, [
        wait, {input, ["from Temporal"]}
    ]).

See: :temporal_sdk_workflow

Start iex -S mix or rebar3 shell and run Temporal workflow execution:

Elixir

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

Erlang

1> hello_world_workflow:start().
HELLO WORLD from Temporal
...

Requirements

The basic config.exs/sys.config configuration files provided above assumes an unsecured Temporal server running on localhost:7233. For development and testing purposes it is recommended to use Temporal CLI:

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