Skip to content

[API Design] Task Helpers #5443

Open
Open
@stevejgordon

Description

@stevejgordon

We should design and add helpers for waiting for a remote server task to complete.

Scenario:

As a developer, I trigger a reindex on the server which may be a long-running operation. I must then query the status of the returned TaskId until it is completed.

var reindex = await _client.ReindexOnServerAsync(r => r
        .Source(s => s.Index("stock-demo-v1"))
        .Destination(d => d.Index("stock-demo-v2"))
        .WaitForCompletion(false), stoppingToken);

    var taskId = reindex.Task;
    var taskResponse = await _client.Tasks.GetTaskAsync(taskId, ct: stoppingToken);
    
    while (!taskResponse.Completed)
    {
        _logger.LogInformation("Waiting for 5 seconds");
        await Task.Delay(TimeSpan.FromSeconds(5), stoppingToken);
        taskResponse = await _client.Tasks.GetTaskAsync(taskId, ct: stoppingToken);
    }

At a minimum, we could add a helper to wait until this is done. This might be a blocking IObserver or perhaps an asynchronous continuation on a user-provided callback.

Further, we could support a timeout which would then cancel the on-going server task.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions