Class PeriodicScheduler
Utility to schedule and manage periodic tasks
Implements
Inherited Members
Namespace: Cognite.Extractor.Common
Assembly: Cognite.Common.dll
Syntax
public class PeriodicScheduler : IDisposable
Constructors
| Edit this page View SourcePeriodicScheduler(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 SourceCount
Number of currently active tasks
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
Methods
| Edit this page View SourceContainsTask(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 |
Dispose()
Dispose of scheduler. Will cancel all running tasks. Do not override this in subclasses.
Declaration
public void Dispose()
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 |
ExitAllAndWait()
Same as calling ExitAndWaitForTermination on all tasks.
Declaration
public Task ExitAllAndWait()
Returns
Type | Description |
---|---|
Task | Task which completes once all tasks are done |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |