Services.Task (fnord v0.8.83)

View Source

Summary

Functions

Appends a new :todo task with the given ID and data to the end of the list. If the list does not exist or the task ID already exists, this call is ignored.

Returns a specification to start this module under a supervisor.

Marks the first task matching task_id as :done and stores the result. Only the first matching ID is updated; others are unchanged. No-op if list or task not found.

Marks the first task matching task_id as :failed and stores the result. Only the first matching ID is updated; others are unchanged. No-op if list or task not found.

Fetches all tasks for the given list in chronological (oldest-first) order. Returns {:error, :not_found} if the list does not exist.

Returns all active task list IDs.

Returns {:ok, task} for the first :todo task in chronological order. Returns {:error, :empty} if no pending tasks, or {:error, :not_found} if the list does not exist.

Inserts a new :todo task with the given ID and data to the front of the list. If the list does not exist or the task ID already exists, this call is ignored.

Types

list_id()

@type list_id() :: non_neg_integer()

task()

@type task() :: %{
  id: task_id(),
  outcome: :todo | :done | :failed,
  data: task_data(),
  result: task_result() | nil
}

task_data()

@type task_data() :: any()

task_id()

@type task_id() :: binary()

task_result()

@type task_result() :: any()

Functions

add_task(list_id, task_id, task_data)

@spec add_task(list_id(), task_id(), task_data()) :: :ok

Appends a new :todo task with the given ID and data to the end of the list. If the list does not exist or the task ID already exists, this call is ignored.

as_string(subject, detail? \\ false)

@spec as_string(list_id() | [task()], boolean()) :: binary()

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

complete_task(list_id, task_id, result)

@spec complete_task(list_id(), task_id(), task_result()) :: :ok

Marks the first task matching task_id as :done and stores the result. Only the first matching ID is updated; others are unchanged. No-op if list or task not found.

fail_task(list_id, task_id, msg)

@spec fail_task(list_id(), task_id(), task_result()) :: :ok

Marks the first task matching task_id as :failed and stores the result. Only the first matching ID is updated; others are unchanged. No-op if list or task not found.

get_list(list_id)

@spec get_list(list_id()) :: [task()] | {:error, :not_found}

Fetches all tasks for the given list in chronological (oldest-first) order. Returns {:error, :not_found} if the list does not exist.

list_ids()

@spec list_ids() :: [list_id()]

Returns all active task list IDs.

peek_task(list_id)

@spec peek_task(list_id()) :: {:ok, task()} | {:error, :not_found} | {:error, :empty}

Returns {:ok, task} for the first :todo task in chronological order. Returns {:error, :empty} if no pending tasks, or {:error, :not_found} if the list does not exist.

push_task(list_id, task_id, task_data)

@spec push_task(list_id(), task_id(), task_data()) :: :ok

Inserts a new :todo task with the given ID and data to the front of the list. If the list does not exist or the task ID already exists, this call is ignored.

start_link(opts \\ [])

@spec start_link(any()) :: GenServer.on_start()

start_list()

@spec start_list() :: list_id()