Class TaskThrottler
Tool to throttle the execution of tasks based on max perallelism, and max number of tasks scheduled per time unit.
Maximum parallelism simply limits the number of parallel tasks.
Per unit sets the maximum number of tasks scheduled per time unit.
Tasks are enqueued and scheduled for execution in order.
Implements
Inherited Members
Namespace: Cognite.Extractor.Common
Assembly: Cognite.Common.dll
Syntax
public sealed class TaskThrottler : IDisposable
Constructors
| Edit this page View SourceTaskThrottler(int, bool, int, TimeSpan?, bool)
Constructor
Declaration
public TaskThrottler(int maxParallelism, bool quitOnFailure = false, int perUnit = 0, TimeSpan? timeUnit = null, bool keepAllResults = false)
Parameters
Type | Name | Description |
---|---|---|
int | maxParallelism | Maximum number of parallel threads |
bool | quitOnFailure | True if |
int | perUnit | |
TimeSpan? | timeUnit | |
bool | keepAllResults | Keep all task result objects, not those who have failed or are within the
last |
Properties
| Edit this page View SourceRunTask
Task for the main task loop in the throttler.
Declaration
public Task RunTask { get; }
Property Value
Type | Description |
---|---|
Task |
Methods
| Edit this page View SourceCheckResult()
Check the result of the scheduler. Throw an error if the task scheduler has failed or if quitOnFailure is true and an error has occured in a task.
Declaration
public void CheckResult()
Dispose()
Dispose of the scheduler. Does not wait for completion and so might leave loose threads.
Declaration
public void Dispose()
EnqueueAndWait(Func<Task>)
Enqueue a task, then wait until it completes before returning its result
Declaration
public Task<TaskResult> EnqueueAndWait(Func<Task> generator)
Parameters
Type | Name | Description |
---|---|---|
Func<Task> | generator | Task to enqueue |
Returns
Type | Description |
---|---|
Task<TaskResult> | Result of task |
EnqueueTask(Func<Task>)
Enqueue a new generator in the task queue to be executed
Declaration
public void EnqueueTask(Func<Task> generator)
Parameters
Type | Name | Description |
---|---|---|
Func<Task> | generator |
WaitForCompletion()
Lock the task queue and wait for all remaining tasks to finish. Returns a list of TaskResult containing information about all scheduled tasks. If any task has failed and quitOnFailure is true, this will throw an exception.
Declaration
public Task<IEnumerable<TaskResult>> WaitForCompletion()
Returns
Type | Description |
---|---|
Task<IEnumerable<TaskResult>> | A list of TaskResult |