barrel_rep_tasks (barrel_docdb v1.1.1)
View Sourcebarrel_rep_tasks - Persistent replication task manager
Manages persistent replication tasks that survive node restarts. Tasks are stored in a dedicated system database and can be: - One-shot: run once and complete - Continuous: keep running and replicate changes as they happen
Starting a Task
%% Start a continuous replication to a remote node
{ok, TaskId} = barrel_rep_tasks:start_task(#{
source => <<"mydb">>,
target => <<"http://remote:8080/db/mydb">>,
mode => continuous,
direction => push
}).Task Lifecycle
Tasks go through these states: - pending: Created but not yet started - running: Currently replicating - paused: Temporarily stopped (can be resumed) - completed: One-shot task finished successfully - failed: Task encountered an error
Summary
Functions
Delete a task (stops it if running)
Get task info
Get the pid for a running task Returns {ok, Pid} if the task is running, {error, not_running} otherwise.
List all tasks
List tasks with filter Filter options: - status: filter by status (running, paused, etc.) - mode: filter by mode (continuous, one_shot)
Pause a running task (can be resumed later)
Resume a paused task
Start the task manager
Start a new replication task Returns the task ID which can be used to manage the task.
Stop the task manager
Stop a running task
Types
-type att_info() :: #{name := binary(), content_type := binary(), length := non_neg_integer(), digest := binary(), chunked => boolean(), chunk_size => pos_integer(), chunk_count => pos_integer()}.
-type change() :: map().
-type db_name() :: binary().
-type docid() :: binary().
-type revid() :: binary().
-type seq() :: barrel_hlc:timestamp().
-type seq_string() :: binary().
-type task() :: #{id := task_id(), config := task_config(), status := task_status(), last_seq => seq() | first, error => binary(), created_at := integer(), updated_at := integer()}.
-type task_config() :: #{source := binary() | map(), target := binary() | map(), mode => task_mode(), direction => task_direction(), source_transport => module(), target_transport => module(), batch_size => pos_integer(), filter => barrel_rep:filter_opts(), wait_for => [binary() | map()]}.
-type task_direction() :: push | pull | both.
-type task_id() :: binary().
-type task_mode() :: one_shot | continuous.
-type task_status() :: pending | running | paused | completed | failed.
-type view_name() :: binary().
Functions
Delete a task (stops it if running)
Get task info
Get the pid for a running task Returns {ok, Pid} if the task is running, {error, not_running} otherwise.
-spec list_tasks() -> {ok, [task()]}.
List all tasks
List tasks with filter Filter options: - status: filter by status (running, paused, etc.) - mode: filter by mode (continuous, one_shot)
Pause a running task (can be resumed later)
Resume a paused task
Start the task manager
-spec start_task(task_config()) -> {ok, task_id()} | {error, term()}.
Start a new replication task Returns the task ID which can be used to manage the task.
-spec stop() -> ok.
Stop the task manager
Stop a running task