Class ExtractorTaskScheduler
Task scheduler that runs tasks and reports their status to the integrations API.
Implements
Inherited Members
Namespace: Cognite.Extractor.Utils.Unstable.Tasks
Assembly: ExtractorUtils.dll
Syntax
public class ExtractorTaskScheduler : IDisposable
Constructors
| Edit this page View SourceExtractorTaskScheduler(IIntegrationSink, ILogger<ExtractorTaskScheduler>)
Constructor.
Declaration
public ExtractorTaskScheduler(IIntegrationSink sink, ILogger<ExtractorTaskScheduler> logger)
Parameters
Type | Name | Description |
---|---|---|
IIntegrationSink | sink | Sink for task updates. |
ILogger<ExtractorTaskScheduler> | logger | Logger object. |
Properties
| Edit this page View SourceCompletedTask
Task that terminates once the run method terminates.
Declaration
public Task CompletedTask { get; }
Property Value
Type | Description |
---|---|
Task |
Methods
| Edit this page View SourceAddScheduledTask(BaseSchedulableTask, bool)
Add a task to the scheduler.
Declaration
public void AddScheduledTask(BaseSchedulableTask operation, bool runImmediately)
Parameters
Type | Name | Description |
---|---|---|
BaseSchedulableTask | operation | Type implementing the runnable task. |
bool | runImmediately | Whether to run the task immediately. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | If a task with the same name already exists. |
CancelInnerAndWait(int, BaseErrorReporter)
Cancel the running task, if it exists.
Declaration
public Task CancelInnerAndWait(int timeoutms, BaseErrorReporter outerReporter)
Parameters
Type | Name | Description |
---|---|---|
int | timeoutms | |
BaseErrorReporter | outerReporter |
Returns
Type | Description |
---|---|
Task |
CancelTask(string)
Cancel a task if it is currently running.
Declaration
public void CancelTask(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | Name of the task to cancel |
Dispose()
Declaration
public void Dispose()
Dispose(bool)
Dispose of the scheduler.
Can be overridden in base classes.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | Whether to dispose managed resources. |
GetRegisteredTasks()
Get a list of registered tasks, used for reporting startup.
Declaration
public IEnumerable<IntegrationTask> GetRegisteredTasks()
Returns
Type | Description |
---|---|
IEnumerable<IntegrationTask> |
Notify()
Wake up the scheduler and tell it to check its tasks again.
Declaration
public void Notify()
Run(CancellationToken)
Run the scheduler.
This should only be called once on a given scheduler.
To re-run it after a crash, the scheduler must be re-initialized.
Declaration
public Task<ExtractorTaskResult> Run(CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | token | Global cancellation token for stopping the entire scheduler. |
Returns
Type | Description |
---|---|
Task<ExtractorTaskResult> |
ScheduleTaskNow(string, bool)
Schedule a task now. If it is already running it will
Declaration
public void ScheduleTaskNow(string name, bool reScheduleIfRunning = false)
Parameters
Type | Name | Description |
---|---|---|
string | name | Name of the task to schedule |
bool | reScheduleIfRunning | If true, re-schedule the task to run again once it finishes. If false, and the task is already running, nothing will happen. |
WaitForNextEndOfTask(string, TimeSpan, CancellationToken)
Wait for the next time the task given by task
ends.
If the task is not currently running, this will wait until it starts running and then ends.
Note that if the task fails, this will re-throw the exception that caused the task failure, or a TaskCanceledException if it was canceled.
Declaration
public Task WaitForNextEndOfTask(string task, TimeSpan timeout, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
string | task | Task to wait for, must be added to the scheduler. |
TimeSpan | timeout | Timeout, set to Timeout.InfiniteTimespan to wait forever. |
CancellationToken | token | Optional cancellation token. |
Returns
Type | Description |
---|---|
Task |
Exceptions
Type | Condition |
---|---|
ArgumentException | If the task does not exist. |
TimeoutException | If waiting for the task to end timed out. |