Skip to content

Commit aae077f

Browse files
authored
Readme entry for state storage (#40)
1 parent 51b9afa commit aae077f

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ A library containing utilities for building extractors in .Net
1717

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

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

2222
Using .NET CLI:
2323
```sh
2424
mkdir NewExtractor
2525
cd NewExtractor
2626
dotnet new console
27-
dotnet add package Cognite.ExtractorUtils -v 1.0.0-alpha-011
27+
dotnet add package Cognite.ExtractorUtils -v 1.0.0-alpha-017
2828
```
2929
## Quickstart
3030

@@ -147,6 +147,35 @@ using (var queue = destination.CreateRawUploadQueue<ColumnsDto>("myDb", "myTable
147147
148148
```
149149

150+
## Using the State Store
151+
```c#
152+
services.AddStateStore();
153+
154+
using (var provider = services.BuildServiceProvider()) {
155+
var stateStore = provider.GetRequiredService<IExtractionStateStore>();
156+
var destination = provider.GetRequiredService<CogniteDestination>();
157+
158+
// Create a state for a node
159+
var myState = new BaseExtractionState("myState");
160+
var states = new [] { myState };
161+
var stateDict = states.ToDictionary(state => state.Id);
162+
163+
await stateStore.RestoreExtarctionState(stateDict, "someTableorcollection", cancellationToken)
164+
165+
// After uploading points cdf, update the ranges in your state
166+
var now = DateTime.UtcNow;
167+
var datapoints = new Dictionary<Identity, IEnumerable<Datapoint>>() {
168+
{ new Identity("myState"), new Datapoint[] { new Datapoint(now - TimeSpan.FromHours(2), "B"), new Datapoint(now, "A")}}}
169+
170+
await destination.InsertDataPointsIgnoreErrorsAsync(datapoints, cancellationToken);
171+
172+
myState.UpdateDestinationRanges(now - TimeSpan.FromHours(2), now);
173+
174+
await stateStore.StoreExtractionState(states, "someTableorcollection", cancellationToken);
175+
// If the extractor stops here, the state is saved and can be restored after restart.
176+
}
177+
```
178+
150179
# Code of Conduct
151180

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

0 commit comments

Comments
 (0)