temporal_sdk_nexus behaviour (temporal_sdk v0.1.14)

View Source

Temporal nexus task module.

WIP. Module will provide Temporal Nexus services.

Summary

Types

cancel_action()

-type cancel_action() :: {cancel, CanceledDetails :: temporal_sdk:term_to_payloads()}.

complete_action()

-type complete_action() :: {complete, Result :: temporal_sdk:term_to_payloads()}.

context()

-type context() ::
          #{cluster := temporal_sdk_cluster:cluster_name(),
            executor_pid := pid(),
            otel_ctx := otel_ctx:t(),
            task := task(),
            worker_opts := temporal_sdk_worker:opts(),
            operation := unicode:chardata(),
            started_at := SystemTime :: integer(),
            task_timeout := erlang:timeout()}.

data()

-type data() :: term().

data_action()

-type data_action() :: {data, NewData :: data()}.

fail_action()

-type fail_action() ::
          {fail,
           {Source :: temporal_sdk:serializable(),
            Message :: temporal_sdk:serializable(),
            Stacktrace :: temporal_sdk:serializable()}}.

handler_context()

-type handler_context() ::
          #{data := data(),
            cancel_requested := boolean(),
            elapsed_time := non_neg_integer(),
            remaining_time := erlang:timeout()}.

task()

terminate_action()

-type terminate_action() :: cancel_action() | complete_action() | fail_action().

Callbacks

execute(Context, RequestPayload)

-callback execute(Context :: context(), RequestPayload :: temporal_sdk:term_from_payload()) ->
                     ResponsePayload :: temporal_sdk:term_to_payload().

handle_cancel(HandlerContext)

(optional)
-callback handle_cancel(HandlerContext :: handler_context()) -> terminate_action() | ignore.

handle_message(HandlerContext, Message)

(optional)
-callback handle_message(HandlerContext :: handler_context(), Message :: term()) ->
                            terminate_action() | data_action() | ignore.

handle_terminate(HandlerContext)

-callback handle_terminate(HandlerContext :: handler_context()) -> any().

Functions

await_data(EtsPattern)

-spec await_data(EtsPattern :: term()) -> {ok, data()} | timeout | invalid_pattern | no_return().

await_data(EtsPattern, Timeout)

-spec await_data(EtsPattern :: term(), Timeout :: erlang:timeout()) ->
                    {ok, data()} | timeout | invalid_pattern | no_return().

cancel(CanceledDetails)

-spec cancel(CanceledDetails :: temporal_sdk:term_to_payloads()) -> no_return().

cancel_requested()

-spec cancel_requested() -> boolean() | no_return().

complete(Result)

-spec complete(Result :: temporal_sdk:term_to_payloads()) -> no_return().

elapsed_time()

-spec elapsed_time() -> NativeTime :: non_neg_integer() | no_return().

elapsed_time(Unit)

-spec elapsed_time(Unit :: erlang:time_unit()) -> non_neg_integer() | no_return().

fail(ApplicationFailure)

get_data()

-spec get_data() -> Data :: data() | no_return().

remaining_time()

-spec remaining_time() -> NativeTime :: non_neg_integer() | infinity | no_return().

remaining_time(Unit)

-spec remaining_time(Unit :: erlang:time_unit()) -> non_neg_integer() | infinity | no_return().

set_data(TaskData)

-spec set_data(TaskData :: term()) -> ok.