IOperationScheduler
Namespace: SnowBank.Threading.Operations · interface
Service that can schedule and run Operations
Methods
Create
IOperationContext<TResult> Create<TResult>(string type, string key, IOperationContext parent = null, CancellationToken ct = null)
Creates a new context for running an operation
type— Operation type (for diagnostic purpose)key— If not null, used to distinguish multiple concurrent operations of the typetypeparent— If not null, parent operation that started this operationct— Token used to abort the execution of the operation
Returns: Context initialized and ready to run
Dispatch
void Dispatch(IOperationContext context, IEvent evt)
Dispatches an event linked to the specified IOperationContext
context— Context of the operation that is triggering this eventevt— Event triggered by this operation
ExecuteOperation
Task<OperationResult<TResult>> ExecuteOperation<TResult>(IOperationContext<TResult> context, Func<IOperationContext<TResult>, Task<OperationResult<TResult>>> handler)
Executes an operation under the control of this scheduler
context— Context of the operationhandler— Handler that will run the operation
Returns: Result of the operation.
Any exception thrown by handler will be intercepted and wrapped into a failed OperationResult.
The end result of the operation can be checked using the Check method.
Log
void Log(IOperationContext context, LogLevel level, Exception exception, string message, params object[] args)
Logs a message that will be visible to the observers of an operation
context— Context of the operation that is producing this loglevel— Log levelexception— Optional exception that is linked to this log messagemessage— Log messageargs— Optional arguments used to format the log message