Exemple #1
0
        private bool IsDisabled(ITask task, Arguments arguments, PreventConcurrentTaskExecutionAttribute preventConcurrent)
        {
            Type runtimeEvaluatorType = preventConcurrent.RuntimeEvaluator;

            if (runtimeEvaluatorType != null)
            {
                if (!(_kernel.Resolve(runtimeEvaluatorType) is IPreventConcurrentTaskExecutionRuntimeEvaluator runtimeEvaluator)
                    )
                {
                    throw new InvalidOperationException($@"Unable to resolve evaluator type '{runtimeEvaluatorType.FullName}' which has been specified on task '{task.GetType().FullName}'. 

Either the type does not implement '{nameof(IPreventConcurrentTaskExecutionRuntimeEvaluator)}'-interface or you forgot to register the type as a custom evaluator. 

You can register custom evaluators when setting up Integration Service in the ApplicationContext.Create(...)-method:

using (IApplicationContext context = ApplicationContext.Create(application => application
    .Tasks(tasks => tasks
        .ConcurrentTaskExecution(concurrentTaskExecution => concurrentTaskExecution
            .AddFromAssemblyOfThis<Program>()
            .AddEvaluator<MyCustomEvaluator>()))");
                }

                if (runtimeEvaluator.Disabled(task, arguments))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #2
0
        private string GetLockName(ITask task, Arguments arguments, PreventConcurrentTaskExecutionAttribute preventConcurrent)
        {
            Type customLockNameType = preventConcurrent?.CustomLockName;

            if (customLockNameType != null)
            {
                if (!(_kernel.Resolve(customLockNameType) is IPreventConcurrentTaskExecutionCustomLockName customLockName))
                {
                    throw new InvalidOperationException(
                              $@"Unable to resolve custom lock name type '{customLockNameType.FullName}' which has been specified on task '{task.GetType().FullName}'. 

Either the type does not implement '{nameof(IPreventConcurrentTaskExecutionCustomLockName)}'-interface or you forgot to register the type as a custom lock name. 

You can register custom evaluators when setting up Integration Service in the ApplicationContext.Create(...)-method:

using (IApplicationContext context = ApplicationContext.Create(application => application
    .Tasks(tasks => tasks
        .ConcurrentTaskExecution(concurrentTaskExecution => concurrentTaskExecution
            .AddFromAssemblyOfThis<Program>()
            .AddCustomLockName<MyCustomLockName>()))");
                }

                string lockName = customLockName.GetLockName(task, arguments);

                if (!string.IsNullOrWhiteSpace(lockName))
                {
                    return(lockName);
                }
            }

            return(task.Name());
        }
Exemple #3
0
        private IPreventConcurrentTaskExecutionExceptionHandler GetExceptionHandler(ITask task, PreventConcurrentTaskExecutionAttribute preventConcurrent)
        {
            Type exceptionHandlerType = preventConcurrent?.ExceptionHandler;

            if (exceptionHandlerType != null)
            {
                if (!(_kernel.Resolve(exceptionHandlerType) is IPreventConcurrentTaskExecutionExceptionHandler exceptionHandler))
                {
                    throw new InvalidOperationException(
                              $@"Unable to resolve exception handler type '{exceptionHandlerType.FullName}' which has been specified on task '{task.GetType().FullName}'. 

Either the type does not implement '{nameof(IPreventConcurrentTaskExecutionExceptionHandler)}'-interface or you forgot to register the type as an exception handler. 

You can register exception handlers when setting up Integration Service in the ApplicationContext.Create(...)-method:

using (IApplicationContext context = ApplicationContext.Create(application => application
    .Tasks(tasks => tasks
        .ConcurrentTaskExecution(concurrentTaskExecution => concurrentTaskExecution
            .AddFromAssemblyOfThis<Program>()
            .AddExceptionHandler<MyExceptionHandler>()))");
                }

                return(exceptionHandler);
            }

            return(null);
        }
Exemple #4
0
        private string GetLockDescription(ITask task, TaskLog log, Arguments arguments, PreventConcurrentTaskExecutionAttribute preventConcurrent)
        {
            string description = $"Acquired by '{task.Name()}'. TaskLogId: {log.Id ?? "<n/a>"}.";

            Type customLockDescriptionType = preventConcurrent?.CustomLockDescription;

            if (customLockDescriptionType != null)
            {
                if (!(_kernel.Resolve(customLockDescriptionType) is IPreventConcurrentTaskExecutionCustomLockDescription customLockDescription))
                {
                    throw new InvalidOperationException(
                              $@"Unable to resolve custom lock description type '{customLockDescriptionType.FullName}' which has been specified on task '{task.GetType().FullName}'. 

Either the type does not implement '{nameof(IPreventConcurrentTaskExecutionCustomLockDescription)}'-interface or you forgot to register the type as a custom lock description. 

You can register custom lock descriptions when setting up Integration Service in the ApplicationContext.Create(...)-method:

using (IApplicationContext context = ApplicationContext.Create(application => application
    .Tasks(tasks => tasks
        .ConcurrentTaskExecution(concurrentTaskExecution => concurrentTaskExecution
            .AddFromAssemblyOfThis<Program>()
            .AddCustomLockDescription<MyCustomLockDescription>()))");
                }

                description = customLockDescription.GetLockDescription(task, arguments, description);
            }

            return(description);
        }