Show / Hide Table of Contents

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.

Inheritance
object
TaskThrottler
Implements
IDisposable
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Cognite.Extractor.Common
Assembly: Cognite.Common.dll
Syntax
public sealed class TaskThrottler : IDisposable

Constructors

| Edit this page View Source

TaskThrottler(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 timeUnit. This means that the size in memory of the task throttler will grow forever, do not use this unless you intend to dispose of the throttler within a short period of time.

Properties

| Edit this page View Source

RunTask

Task for the main task loop in the throttler.

Declaration
public Task RunTask { get; }
Property Value
Type Description
Task

Methods

| Edit this page View Source

CheckResult()

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()
| Edit this page View Source

Dispose()

Dispose of the scheduler. Does not wait for completion and so might leave loose threads.

Declaration
public void Dispose()
| Edit this page View Source

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

| Edit this page View Source

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
| Edit this page View Source

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

Implements

IDisposable

Extension Methods

DataModelUtils.GetOrCreateResourcesAsync<T, T2>(T2, IEnumerable<InstanceIdentifier>, Func<IEnumerable<InstanceIdentifier>, IEnumerable<SourcedNodeWrite<T>>>, Func<IEnumerable<SourcedNodeWrite<T>>, SanitationMode, (IEnumerable<SourcedNodeWrite<T>>, IEnumerable<CogniteError<SourcedNodeWrite<T>>>)>, int, int, RetryMode, SanitationMode, CancellationToken)
  • Edit this page
  • View Source
In this article
Back to top Generated by DocFX