Ongoing Task Operations


Get ongoing task info

For the examples in this article, let's create a simple external replication ongoing task:

// Define a simple External Replication task
var taskDefintion = new ExternalReplication
{
    Name = "MyExtRepTask",
    ConnectionStringName = "MyConnectionStringName"
};

// Deploy the task to the server
var taskOp = new UpdateExternalReplicationOperation(taskDefintion);
var sendResult = store.Maintenance.Send(taskOp);

// The task ID is available in the send result
var taskId = sendResult.TaskId;

Use GetOngoingTaskInfoOperation to get information about an ongoing task.

// Define the get task operation, pass:
// * The ongoing task ID or the task name
// * The task type 
var getTaskInfoOp = new GetOngoingTaskInfoOperation(taskId, OngoingTaskType.Replication);

// Execute the operation by passing it to Maintenance.Send
var taskInfo = (OngoingTaskReplication)store.Maintenance.Send(getTaskInfoOp);

// Access the task info
var taskState = taskInfo.TaskState;
var taskDelayTime = taskInfo.DelayReplicationFor;
var destinationUrls= taskInfo.TopologyDiscoveryUrls;
// ...
var getTaskInfoOp = new GetOngoingTaskInfoOperation(taskId, OngoingTaskType.Replication);
var taskInfo = (OngoingTaskReplication) await store.Maintenance.SendAsync(getTaskInfoOp);

var taskState = taskInfo.TaskState;
var taskDelayTime = taskInfo.DelayReplicationFor;
var destinationUrls= taskInfo.TopologyDiscoveryUrls;
// ...

Delete ongoing task

Use DeleteOngoingTaskOperation to remove an ongoing task from the list of tasks assigned to the database.

// Define the delete task operation, pass:
// * The ongoing task ID
// * The task type 
var deleteTaskOp = new DeleteOngoingTaskOperation(taskId, OngoingTaskType.Replication);

// Execute the operation by passing it to Maintenance.Send
store.Maintenance.Send(deleteTaskOp);
var deleteTaskOp = new DeleteOngoingTaskOperation(taskId, OngoingTaskType.Replication);
await store.Maintenance.SendAsync(deleteTaskOp);

Toggle ongoing task state

Use ToggleOngoingTaskStateOperation to enable/disable the task state.

// Define the delete task operation, pass:
// * The ongoing task ID
// * The task type
// * A boolean value to enable/disable
var toggleTaskOp = new ToggleOngoingTaskStateOperation(taskId, OngoingTaskType.Replication, true);

// Execute the operation by passing it to Maintenance.Send
store.Maintenance.Send(toggleTaskOp);
var toggleTaskOp = new ToggleOngoingTaskStateOperation(taskId, OngoingTaskType.Replication, true);
await store.Maintenance.SendAsync(toggleTaskOp);

Syntax

// Get
public GetOngoingTaskInfoOperation(long taskId, OngoingTaskType type);
public GetOngoingTaskInfoOperation(string taskName, OngoingTaskType type);

// Delete
public DeleteOngoingTaskOperation(long taskId, OngoingTaskType taskType);

// Toggle
public ToggleOngoingTaskStateOperation(long taskId, OngoingTaskType type, bool disable);
Parameter Type Description
taskId long Task ID
taskName string Task name
taskType OngoingTaskType Task type
disable bool true - disable the task
false - enable the task

private enum OngoingTaskType
{
    Replication,
    RavenEtl,
    SqlEtl,
    OlapEtl,
    ElasticSearchEtl,
    QueueEtl,
    Backup,
    Subscription,
    PullReplicationAsHub,
    PullReplicationAsSink,
    QueueSink,
}


Return value of store.Maintenance.Send(GetOngoingTaskInfoOperation)
OngoingTaskReplication Object with information about the task

public sealed class OngoingTaskReplication : OngoingTask
{
    public OngoingTaskReplication() => this.TaskType = OngoingTaskType.Replication;
    public string DestinationUrl { get; set; }
    public string[] TopologyDiscoveryUrls { get; set; }
    public string DestinationDatabase { get; set; }
    public string ConnectionStringName { get; set; }
    public TimeSpan DelayReplicationFor { get; set; }
}