Show / Hide Table of Contents

Class PeriodicScheduler

Utility to schedule and manage periodic tasks

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

Constructors

| Edit this page View Source

PeriodicScheduler(CancellationToken)

Constructor.

Declaration
public PeriodicScheduler(CancellationToken token)
Parameters
Type Name Description
CancellationToken token

Cancellation token linked to all running tasks

Properties

| Edit this page View Source

Count

Number of currently active tasks

Declaration
public int Count { get; }
Property Value
Type Description
int

Methods

| Edit this page View Source

ContainsTask(string)

Returns true if a task with the given name exists

Declaration
public bool ContainsTask(string name)
Parameters
Type Name Description
string name

Task to check

Returns
Type Description
bool

True if task identified by name exists

| Edit this page View Source

Dispose()

Dispose of scheduler. Will cancel all running tasks. Do not override this in subclasses.

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

Dispose(bool)

Dispose of scheduler. Will cancel all running tasks. Override this in subclasses.

Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
bool disposing

True to dispose

| Edit this page View Source

ExitAllAndWait(int)

Same as calling ExitAndWaitForTermination on all tasks.

Declaration
public Task ExitAllAndWait(int timeoutMs = 0)
Parameters
Type Name Description
int timeoutMs
Returns
Type Description
Task

Task which completes once all tasks are done

| Edit this page View Source

ExitAndWaitForTermination(string)

Signal a task should terminate then wait. This will not cancel the operation if it is running, but wait for it to terminate. Will throw an exception if the task has failed.

Declaration
public Task ExitAndWaitForTermination(string name)
Parameters
Type Name Description
string name

Name of task to cancel

Returns
Type Description
Task

Task which completes once the task has terminated

| Edit this page View Source

SchedulePeriodicTask(string?, ITimeSpanProvider, Action<CancellationToken>, bool)

Schedule a new periodic task to run with interval interval. Exceptions are not caught, so operation should catch its own errors, or the task from WaitForAll should be watched.

Declaration
public void SchedulePeriodicTask(string? name, ITimeSpanProvider interval, Action<CancellationToken> operation, bool runImmediately = true)
Parameters
Type Name Description
string name

Name of task, used to refer to it later

ITimeSpanProvider interval

Interval to schedule on

Action<CancellationToken> operation

Function to call on each iteration

bool runImmediately

True to execute the periodic task immediately, false to first wait until triggered by interval or manually

| Edit this page View Source

SchedulePeriodicTask(string?, ITimeSpanProvider, Func<CancellationToken, Task>, bool)

Schedule a new periodic task to run with interval interval. Exceptions are not caught, so operation should catch its own errors, or the task from WaitForAll should be watched.

Declaration
public void SchedulePeriodicTask(string? name, ITimeSpanProvider interval, Func<CancellationToken, Task> operation, bool runImmediately = true)
Parameters
Type Name Description
string name

Name of task, used to refer to it later

ITimeSpanProvider interval

Interval to schedule on

Func<CancellationToken, Task> operation

Function to call on each iteration

bool runImmediately

True to execute the periodic task immediately, false to first wait until triggered by interval or manually

| Edit this page View Source

SchedulePeriodicTask(string?, TimeSpan, Action<CancellationToken>, bool)

Schedule a new periodic task to run with interval interval. Exceptions are not caught, so operation should catch its own errors, or the task from WaitForAll should be watched.

Declaration
public void SchedulePeriodicTask(string? name, TimeSpan interval, Action<CancellationToken> operation, bool runImmediately = true)
Parameters
Type Name Description
string name

Name of task, used to refer to it later

TimeSpan interval

Interval to schedule on

Action<CancellationToken> operation

Function to call on each iteration

bool runImmediately

True to execute the periodic task immediately, false to first wait until triggered by interval or manually

| Edit this page View Source

SchedulePeriodicTask(string?, TimeSpan, Func<CancellationToken, Task>, bool)

Schedule a new periodic task to run with interval interval. Exceptions are not caught, so operation should catch its own errors, or the task from WaitForAll should be watched.

Declaration
public void SchedulePeriodicTask(string? name, TimeSpan interval, Func<CancellationToken, Task> operation, bool runImmediately = true)
Parameters
Type Name Description
string name

Name of task, used to refer to it later

TimeSpan interval

Interval to schedule on

Func<CancellationToken, Task> operation

Function to call on each iteration

bool runImmediately

True to execute the periodic task immediately, false to first wait until triggered by interval or manually

| Edit this page View Source

ScheduleTask(string?, Action<CancellationToken>)

Schedule a new task to run with on the scheduler. Exceptions are not caught, so operation should catch its own errors, or the task from WaitForAll should be watched. Note that this method waits on operation to yield, so make sure that it does not contain too much synchronous code.

Declaration
public void ScheduleTask(string? name, Action<CancellationToken> operation)
Parameters
Type Name Description
string name
Action<CancellationToken> operation
| Edit this page View Source

ScheduleTask(string?, Func<CancellationToken, Task>)

Schedule a new task to run with on the scheduler. Exceptions are not caught, so operation should catch its own errors, or the task from WaitForAll should be watched. Note that this method waits on operation to yield, so make sure that it does not contain too much synchronous code.

Declaration
public void ScheduleTask(string? name, Func<CancellationToken, Task> operation)
Parameters
Type Name Description
string name
Func<CancellationToken, Task> operation
| Edit this page View Source

TryPauseTask(string, bool)

Set the paused state of the named task. In this state it will only trigger when manually triggered. Same as setting the timespan to infinite when creating the task. The task will trigger when unpaused.

Declaration
public bool TryPauseTask(string name, bool paused)
Parameters
Type Name Description
string name

Name of task to pause

bool paused

True to pause the task, false to unpause

Returns
Type Description
bool

True if the task was paused

| Edit this page View Source

TryTriggerTask(string)

Manually trigger a task. The task will always run after this, but may run twice if it is about to run due to timeout. Either way the task will always run after this.

Declaration
public bool TryTriggerTask(string name)
Parameters
Type Name Description
string name
Returns
Type Description
bool

True if the task was triggered

| Edit this page View Source

WaitForAll()

Returns the internal task monitoring all running tasks. It will fail if any internal task fails.

Declaration
public Task WaitForAll()
Returns
Type Description
Task
| Edit this page View Source

WaitForTermination(string)

Waits for a task to terminate. If it is periodic this may never happen.

Declaration
public Task WaitForTermination(string name)
Parameters
Type Name Description
string name

Name of task to wait for

Returns
Type Description
Task

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