Services.Task (fnord v0.9.11)

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 true if there are no remaining :todos in the list.

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 the description of the specified task list. Returns {:ok, description} or {: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.

Fetches tasks and description for the given list in a single call. Returns {:ok, tasks, description} or {:error, :not_found}.

Returns all active task list IDs.

Creates a new task with the given ID and data. Optionally accepts :outcome (default :todo) and :result (default nil).

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.

Updates the description of the specified task list. Returns :ok or {:error, :not_found} if the list does not exist.

Create a new task list with an optional slug id and description. If no id is provided, a unique slug of the form "tasks-<n>" is generated. If the id already exists, returns {:error, :exists}.

Types

list_id()

@type list_id() :: binary()

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_list()

@type task_list() :: [task()]

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.

all_tasks_complete?(list_id)

@spec all_tasks_complete?(list_id()) :: {:ok, boolean()}

Returns true if there are no remaining :todos in the list.

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_description(list_id)

@spec get_description(list_id()) :: {:ok, binary() | nil} | {:error, :not_found}

Fetches the description of the specified task list. Returns {:ok, description} or {:error, :not_found}.

get_list(list_id)

@spec get_list(list_id()) :: task_list() | {: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.

get_list_with_description(list_id)

@spec get_list_with_description(list_id()) ::
  {:ok, task_list(), binary() | nil} | {:error, :not_found}

Fetches tasks and description for the given list in a single call. Returns {:ok, tasks, description} or {:error, :not_found}.

list_ids()

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

Returns all active task list IDs.

new_task(task_id, data, opts \\ [])

@spec new_task(task_id(), task_data(), keyword()) :: task()

Creates a new task with the given ID and data. Optionally accepts :outcome (default :todo) and :result (default nil).

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.

set_description(list_id, description)

@spec set_description(list_id(), binary()) :: :ok | {:error, :not_found}

Updates the description of the specified task list. Returns :ok or {:error, :not_found} if the list does not exist.

start_link(opts \\ [])

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

start_list()

@spec start_list() :: list_id()

start_list(opts)

@spec start_list(
  %{optional(:id) => binary(), optional(:description) => binary()}
  | binary()
) ::
  list_id() | {:error, :exists}

Create a new task list with an optional slug id and description. If no id is provided, a unique slug of the form "tasks-<n>" is generated. If the id already exists, returns {:error, :exists}.