Skip to content

Commit

Permalink
Readme entry for state storage (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
einarmo authored Jun 22, 2020
1 parent 51b9afa commit aae077f
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ A library containing utilities for building extractors in .Net

The Cognite Extractor Utils can be downloaded from [NuGet](https://www.nuget.org/packages/Cognite.ExtractorUtils).

To create a console application and add the **1.0.0-alpha-011** version of library:
To create a console application and add the **1.0.0-alpha-017** version of library:

Using .NET CLI:
```sh
mkdir NewExtractor
cd NewExtractor
dotnet new console
dotnet add package Cognite.ExtractorUtils -v 1.0.0-alpha-011
dotnet add package Cognite.ExtractorUtils -v 1.0.0-alpha-017
```
## Quickstart

Expand Down Expand Up @@ -147,6 +147,35 @@ using (var queue = destination.CreateRawUploadQueue<ColumnsDto>("myDb", "myTable
```

## Using the State Store
```c#
services.AddStateStore();
using (var provider = services.BuildServiceProvider()) {
var stateStore = provider.GetRequiredService<IExtractionStateStore>();
var destination = provider.GetRequiredService<CogniteDestination>();
// Create a state for a node
var myState = new BaseExtractionState("myState");
var states = new [] { myState };
var stateDict = states.ToDictionary(state => state.Id);
await stateStore.RestoreExtarctionState(stateDict, "someTableorcollection", cancellationToken)
// After uploading points cdf, update the ranges in your state
var now = DateTime.UtcNow;
var datapoints = new Dictionary<Identity, IEnumerable<Datapoint>>() {
{ new Identity("myState"), new Datapoint[] { new Datapoint(now - TimeSpan.FromHours(2), "B"), new Datapoint(now, "A")}}}
await destination.InsertDataPointsIgnoreErrorsAsync(datapoints, cancellationToken);
myState.UpdateDestinationRanges(now - TimeSpan.FromHours(2), now);
await stateStore.StoreExtractionState(states, "someTableorcollection", cancellationToken);
// If the extractor stops here, the state is saved and can be restored after restart.
}
```

# Code of Conduct

This project follows https://www.contributor-covenant.org
Expand Down

0 comments on commit aae077f

Please sign in to comment.