Class TaskRunnerBase
The base class for processing and executing tasks on either a server process or the client itself
Inherited Members
Namespace: LemonEdge.API.Tasks
Assembly: API.dll
Syntax
public abstract class TaskRunnerBase : IDisposable, ITaskRunner, IProcessor
Constructors
TaskRunnerBase(IServerTask, IEntityUpdater, String, IReadOnlyCache, UserInfo, BusyProgressReporter)
Creates a new instance of a Task Runner
Declaration
public TaskRunnerBase(IServerTask task, IEntityUpdater updater, string dbAlias, IReadOnlyCache cache, UserInfo user, BusyProgressReporter reporter)
Parameters
Type | Name | Description |
---|---|---|
IServerTask | task | The instance of the task to be processed. |
IEntityUpdater | updater | A context to use by default for processing this task, thought the task can create its own contexts if required. |
System.String | dbAlias | The db alias for the currently connected database this task is executing against |
IReadOnlyCache | cache | A local context cache |
UserInfo | user | The user this task should be processed under |
BusyProgressReporter | reporter | A class for logging and/or reporting progress of the task back to the client |
Properties
Cache
A local cache for performance
Declaration
public IReadOnlyCache Cache { get; }
Property Value
Type | Description |
---|---|
IReadOnlyCache |
CancelTokenSource
The cancellation token for cancelling the running task.
The task process itself must check and respond to this
Declaration
public CancellationTokenSource CancelTokenSource { get; }
Property Value
Type | Description |
---|---|
System.Threading.CancellationTokenSource |
DBAlias
The current connected database alias the task is running against.
Used for tasks that store results in files using WriteStream(String, String, Stream)
Declaration
public string DBAlias { get; }
Property Value
Type | Description |
---|---|
System.String |
FailedException
If the processing of this task failed through an exception being thrown, this holds the failed exception
Declaration
public Exception FailedException { get; }
Property Value
Type | Description |
---|---|
System.Exception |
Processor
The processor responsible for processing the Task
Declaration
public ITaskProcessor Processor { get; }
Property Value
Type | Description |
---|---|
ITaskProcessor |
Reporter
A reporter to provide feedback to a log, or client depending on the context the process is running under
Declaration
public BusyProgressReporter Reporter { get; set; }
Property Value
Type | Description |
---|---|
BusyProgressReporter |
RunningOnServer
Indicates if this task runner is running on a service directly connected to the database, or through a client
Declaration
protected abstract bool RunningOnServer { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Status
The current status of the task
Declaration
public ServerTaskStatus Status { get; }
Property Value
Type | Description |
---|---|
ServerTaskStatus |
Task
The current task being processed by this task runner
Declaration
public IServerTask Task { get; }
Property Value
Type | Description |
---|---|
IServerTask |
TaskData
The current task data being processed by this task runner
Declaration
public IServerTaskData TaskData { get; }
Property Value
Type | Description |
---|---|
IServerTaskData |
TaskIsVirtual
Indicates the task is a fake task not actually saved in the database, so it should not be updated
By default this is false, indicating the processor is executing real tasks and should update their status, results, etc when complete
When true this is used by the client to create virtual tasks to just immediately process certain tasks, but can not have their status/etc updated when complete as they do not existDeclaration
protected virtual bool TaskIsVirtual { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
TimeCancelled
If this task has been cancelled this holds the datetime stamp it was cancelled
Declaration
public DateTime? TimeCancelled { get; }
Property Value
Type | Description |
---|---|
System.Nullable<System.DateTime> |
TimeFinished
Once this task has completed processing this holds the datetime stamp it completed
Declaration
public DateTime? TimeFinished { get; }
Property Value
Type | Description |
---|---|
System.Nullable<System.DateTime> |
TimeStarted
The datetime stamp the processing of this task was started
Declaration
public DateTime TimeStarted { get; }
Property Value
Type | Description |
---|---|
System.DateTime |
Updater
A context to ensure the process can query, load and modify all LemonEdge data
Declaration
public IEntityUpdater Updater { get; }
Property Value
Type | Description |
---|---|
IEntityUpdater |
User
The current logged in user the process is running under
Declaration
public UserInfo User { get; }
Property Value
Type | Description |
---|---|
UserInfo |
Methods
AbortThread()
Kills the active thread processing the task if the task was processed from RunOnNewThread()
Declaration
public void AbortThread()
Cancel()
Cancels the processing of this task. The task processor (ITaskProcessor implementation) itself must respond to the cancellation token.
Declaration
public Task Cancel()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
CreateTaskHandler()
Creates a new handler for processing the results of a task.
Can be different for client handlers versus server handlers.
Declaration
protected abstract ITaskResultHandler CreateTaskHandler()
Returns
Type | Description |
---|---|
ITaskResultHandler | A new handler for processing the results of a task |
CreateUpdater()
Creates a new instance of a context for the task to process with. The caller is responsible for disposing it after use.
Declaration
public Task<IEntityUpdater> CreateUpdater()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<IEntityUpdater> | A new instance of a context for the task to process with |
Dispose()
Declaration
public void Dispose()
Dispose(Boolean)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
DisposeManaged()
Declaration
protected virtual void DisposeManaged()
FlushPendingMessages()
Used for cleaning up a task runner before disposing of it.
Flushes all messages against the Reporter
Declaration
public Task FlushPendingMessages()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task |
InternalCreateUpdater()
Creates a new updater context
Declaration
protected abstract Task<IEntityUpdater> InternalCreateUpdater()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<IEntityUpdater> | A new updater context |
Kill()
If cancel does not cancel the task within enough time, kill can be used to set the task status to cancelled preventing any other processing even if the process completes
Declaration
public Task Kill()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A task indicating the completion of the operation |
LogError(Exception, String)
Writes any error processing the system to the log
Can be overridden by implementing classes to log errors elsewhere too
Declaration
protected virtual void LogError(Exception ex, string msg)
Parameters
Type | Name | Description |
---|---|---|
System.Exception | ex | The exception being logged |
System.String | msg | The message for the exception |
Run()
Runs the processing of this Task as a task
Declaration
public Task Run()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A task indicating the completion of processing this Task |
RunInternal()
Processes the Task, handling reporting, results, exceptions, and status updates
Declaration
protected virtual Task RunInternal()
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task | A task indicating the completion of the Task |
RunOnNewThread()
Runs the processing of this Task on a new thread
Declaration
public void RunOnNewThread()
SetTaskData(IServerTaskData)
Adds the specified task data as the data for this task
Declaration
protected void SetTaskData(IServerTaskData data)
Parameters
Type | Name | Description |
---|---|---|
IServerTaskData | data |