View Source WorkflowMetal.Task.Task (workflow_metal v0.2.1)

A GenStateMachine to lock tokens and generate workitem.

storage

Storage

The data of :token_table is stored in ETS in the following format:

{token_id, token_schema, token_state}

The data of :workitem_table is stored in ETS in the following format:

{workitem_id, workitem_state}

state

State

started+-------->allocated+------->executing+------->completed
    +                +                 +
    |                |                 |
    |                v                 |
    +----------->abandoned<------------+

restore

Restore

Restore a task while restoring its non-ending(created and started) workitems.

Link to this section Summary

Functions

Returns a specification to start this module under a supervisor.

Discard tokens when the case withdraw them.

Abandon the task forcibly.

Pre-execute the given task, return with locked tokens.

Receive tokens from the case.

Update the state of a workitem in the workitem_table.

Link to this section Types

Specs

application() :: WorkflowMetal.Application.t()

Specs

Specs

on_preexecute() ::
  {:ok, [token_schema(), ...]}
  | {:error, :tokens_not_available}
  | {:error, :task_not_enabled}

Specs

options() :: [name: term(), task_schema: task_schema()]

Specs

Specs

t() :: %WorkflowMetal.Task.Task{
  application: application() | nil,
  task_schema: task_schema() | nil,
  token_table: :ets.tid() | nil,
  transition_schema: transition_schema() | nil,
  workitem_table: :ets.tid() | nil
}

Specs

task_id() :: WorkflowMetal.Storage.Schema.Task.id()

Specs

task_schema() :: WorkflowMetal.Storage.Schema.Task.t()

Specs

Specs

Specs

Specs

Specs

Specs

Specs

workitem_id() :: WorkflowMetal.Storage.Schema.Workitem.id()

Specs

workitem_schema() :: WorkflowMetal.Storage.Schema.Workitem.t()

Specs

workitem_state() :: WorkflowMetal.Storage.Schema.Workitem.state()

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

discard_tokens(task_server, token_schemas)

View Source

Specs

discard_tokens(:gen_statem.server_ref(), [token_schema()]) :: :ok

Discard tokens when the case withdraw them.

eg: these tokens has been locked by the other token.

Link to this function

force_abandon(task_server)

View Source

Specs

force_abandon(:gen_statem.server_ref()) :: :ok

Abandon the task forcibly.

Specs

Pre-execute the given task, return with locked tokens.

lock-tokens

Lock tokens

If tokens are already locked by the task, return :ok too.

When the task is not enabled, return {:error, :task_not_enabled}. When fail to lock tokens, return {:error, :tokens_not_available}.

Link to this function

receive_tokens(task_server, token_schemas)

View Source

Specs

receive_tokens(:gen_statem.server_ref(), [token_schema()]) :: :ok

Receive tokens from the case.

Link to this function

update_workitem(task_server, workitem_id, workitem_state)

View Source

Specs

update_workitem(:gen_statem.server_ref(), workitem_id(), workitem_state()) ::
  :ok

Update the state of a workitem in the workitem_table.