temporal_sdk_api (temporal_sdk v0.1.15)

View Source

Temporal API functions and helpers module.

Summary

Types

activity_task_opts()

-type activity_task_opts() ::
          #{token := unicode:chardata() | undefined, index_key => temporal_sdk_workflow:activity()}.

context()

-type context() ::
          #{cluster := temporal_sdk_cluster:cluster_name(),
            enable_single_distributed_workflow_execution => boolean() | undefined,
            workflow_scope => temporal_sdk_node:scope_config() | scope() | undefined,
            client_opts => temporal_sdk_client:opts(),
            worker_opts => temporal_sdk_worker:opts(),
            task_opts => activity_task_opts() | workflow_task_opts(),
            worker_type => temporal_sdk_worker:worker_type(),
            worker_identity => temporal_sdk:serializable(),
            limiter_counters => [[counters:counters_ref()]],
            execution_module => module()}.

scope()

-type scope() ::
          #{scope := temporal_sdk_cluster:cluster_name(),
            shard_size := pos_integer(),
            shard_id => non_neg_integer(),
            ets_scope_id => atom(),
            pg_scope_id => atom()}.

temporal_service()

-type temporal_service() :: temporal_sdk_proto:service().

workflow_task_opts()

-type workflow_task_opts() ::
          #{token := unicode:chardata() | undefined,
            next_page_token => unicode:chardata(),
            workflow_type := unicode:chardata(),
            workflow_id := unicode:chardata(),
            run_id := unicode:chardata(),
            sticky_attributes :=
                temporal_sdk_proto_service_workflow_binaries:'temporal.api.taskqueue.v1.StickyExecutionAttributes'()}.

Functions

from_payload_mapper(Cluster, MsgName, Key, Position, Data)

-spec from_payload_mapper(Cluster :: temporal_sdk_cluster:cluster_name(),
                          MsgName :: temporal_sdk_client:msg_name(),
                          Key :: term(),
                          Position :: pos_integer(),
                          Data :: temporal_sdk:temporal_payload()) ->
                             Arg :: temporal_sdk:term_from_payload().

Mapping from Temporal payload temporal_sdk:temporal_payload/0 to Erlang term temporal_sdk:term_from_payload/0.

Function used as a default value in the SDK gRPC client gRPC helpers from_payload_mapper configuration option.

id(Cluster, MsgName, IdKey, Msg)

-spec id(Cluster :: temporal_sdk_cluster:cluster_name(),
         MsgName :: temporal_sdk_client:msg_name(),
         IdKey :: term(),
         Msg :: map()) ->
            unicode:chardata().

Generates Temporal API gRPC request identifier.

Returns the Temporal API gRPC request identifier as a string generated from:

  • the cluster name,
  • optionally, the activity or workflow type,
  • and a UUID4.

Function used as a default value in the SDK gRPC client gRPC helpers id configuration option.

Example:

1> temporal_sdk_api:id(
    cluster_1,
    'temporal.api.workflowservice.v1.StartWorkflowExecutionRequest',
    request_id,
    #{workflow_type => #{name => "test_workflow"}}
   ).
"cluster_1-test_workflow-b6a1141b-3193-4008-b9c3-c0327015bb3e"

identity(Cluster, MsgName, Identity)

-spec identity(Cluster :: temporal_sdk_cluster:cluster_name(),
               MsgName :: temporal_sdk_client:msg_name(),
               Identity :: temporal_sdk:serializable()) ->
                  unicode:chardata().

Generates Temporal API gRPC request worker and client identities.

Returns the Temporal API gRPC request worker or client identity as a string generated from:

  • the hostname, obtained by calling: {ok, Hostname} = inet:gethostname(),
  • the Erlang node name, obtained by calling: node(),
  • the cluster name,
  • the local worker or client identity.

Function used as a default value in the SDK gRPC client gRPC helpers identity configuration option.

Example:

1> temporal_sdk_api:identity(
    cluster_1, 'temporal.api.workflowservice.v1.PollWorkflowTaskQueueRequest', [w1, workflow, 1]
   ).
"hostname/nonode@nohost/cluster_1/w1/workflow/1"

is_retryable(Result, RequestInfo, Attempt)

-spec is_retryable(Result :: temporal_sdk_grpc:result(),
                   RequestInfo :: temporal_sdk_grpc:request_info(),
                   Attempt :: pos_integer()) ->
                      boolean().

request(ServiceName, Cluster, Msg)

-spec request(ServiceName :: temporal_service(),
              Cluster :: temporal_sdk_cluster:cluster_name(),
              Msg :: temporal_sdk_client:msg()) ->
                 Result :: temporal_sdk_client:call_result().

gRPC request function.

Same as: request(ServiceName, Cluster, Msg, call, #{}).

request/5

-spec request(ServiceName :: temporal_service(),
              Cluster :: temporal_sdk_cluster:cluster_name(),
              Msg :: temporal_sdk_client:msg(),
              ReqType,
              EnvGrpcOpts :: temporal_sdk_client:grpc_opts()) ->
                 Result :: temporal_sdk_client:call_result()
                 when ReqType :: call_formatted;
             (ServiceName :: temporal_service(),
              Cluster :: temporal_sdk_cluster:cluster_name(),
              Msg :: temporal_sdk_client:msg(),
              ReqType,
              EnvGrpcOpts :: temporal_sdk_client:grpc_opts()) ->
                 Result :: temporal_sdk_client:call_result()
                 when ReqType :: call;
             (ServiceName :: temporal_service(),
              Cluster :: temporal_sdk_cluster:cluster_name(),
              Msg :: temporal_sdk_client:msg(),
              ReqType,
              EnvGrpcOpts :: temporal_sdk_client:grpc_opts()) ->
                 Result :: temporal_sdk_client:cast_result()
                 when ReqType :: cast;
             (ServiceName :: temporal_service(),
              Cluster :: temporal_sdk_cluster:cluster_name(),
              Msg :: temporal_sdk_client:msg(),
              ReqType,
              EnvGrpcOpts :: temporal_sdk_client:grpc_opts()) ->
                 Result :: temporal_sdk_client:msg_result()
                 when ReqType :: msg.

gRPC request function.

Example:

1> temporal_sdk_api:request('ListClusters', cluster_1, #{}, cast, #{}).
ok
2> temporal_sdk_api:request('ListClusters', cluster_1, #{}, call, #{}).
{ok,#{clusters =>
          [#{address => <<"127.0.0.1:7233">>,
             cluster_id => <<"e890d347-3100-4c73-953c-e1a5441215ab">>,
             cluster_name => <<"active">>,history_shard_count => 1,
             initial_failover_version => 1,
             http_address => <<"127.0.0.1:41771">>,
             is_connection_enabled => true}],
      next_page_token => <<>>}}
3> temporal_sdk_api:request('ListClusters', cluster_1, #{}, msg, #{}).
#Ref<0.4097329788.374603782.28828>
4> flush().
Shell got {temporal_sdk_grpc_response,#Ref<0.4097329788.374603782.28828>,
              {ok,#{clusters =>
                        [#{address => <<"127.0.0.1:7233">>,
                           cluster_id =>
                               <<"e890d347-3100-4c73-953c-e1a5441215ab">>,
                           cluster_name => <<"active">>,
                           history_shard_count => 1,
                           initial_failover_version => 1,
                           http_address => <<"127.0.0.1:41771">>,
                           is_connection_enabled => true}],
                    next_page_token => <<>>}}}
ok

serializer(Cluster, MsgName, Key, Term)

-spec serializer(Cluster :: temporal_sdk_cluster:cluster_name(),
                 MsgName :: temporal_sdk_client:msg_name(),
                 Key :: term(),
                 Term :: temporal_sdk:serializable()) ->
                    unicode:chardata().

Serializes Erlang terms to Unicode characters before sending them to the Temporal server.

Function used as a default value in the SDK gRPC client gRPC helpers serializer configuration option.

session_task_queue_name(Cluster, Namespace, ParentTaskQueueName)

-spec session_task_queue_name(Cluster :: temporal_sdk_cluster:cluster_name(),
                              Namespace :: unicode:chardata(),
                              ParentTaskQueueName :: unicode:chardata()) ->
                                 unicode:chardata().

temporal_name_to_erlang(Cluster, TemporalTypeName)

-spec temporal_name_to_erlang(Cluster :: temporal_sdk_cluster:cluster_name(),
                              TemporalTypeName :: unicode:chardata()) ->
                                 {ok, module()} | {error, {Reason :: string(), Details :: map()}}.

to_payload_mapper(Cluster, MsgName, Key, Position, Data)

-spec to_payload_mapper(Cluster :: temporal_sdk_cluster:cluster_name(),
                        MsgName :: temporal_sdk_client:msg_name(),
                        Key :: term(),
                        Position :: pos_integer(),
                        Data :: temporal_sdk:term_to_payload()) ->
                           Payload :: temporal_sdk:temporal_payload().

Mapping from Erlang term temporal_sdk:term_to_payload/0 to Temporal payload temporal_sdk:temporal_payload/0.

Function used as a default value in the SDK gRPC client gRPC helpers to_payload_mapper configuration option.