public static void Enqueue([NotNull] this ITaskQueueService queueService, [NotNull] Func <Task> func)
        {
            Check.NotNull(queueService, nameof(queueService));
            Check.NotNull(func, nameof(func));

            queueService.Enqueue(new DelegateQueueableTask(ctx => func()));
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskQueueHostedService"/> class.
 /// </summary>
 /// <param name="serviceScopeFactory"></param>
 /// <param name="taskQueueService"></param>
 /// <param name="logger"></param>
 public TaskQueueHostedService(
     [NotNull] IServiceScopeFactory serviceScopeFactory,
     [NotNull] ITaskQueueService taskQueueService,
     ILogger <TaskQueueHostedService> logger)
     : this(serviceScopeFactory, taskQueueService, NullTaskExceptionHandler.Instance, logger)
 {
 }
        public static void Enqueue([NotNull] this ITaskQueueService queueService,
                                   [NotNull] Func <QueuedTaskExecutionContext, Task> func)
        {
            Check.NotNull(queueService, nameof(queueService));
            Check.NotNull(func, nameof(func));

            queueService.Enqueue(new DelegateQueueableTask(func));
        }
        public static void Enqueue <T>([NotNull] this ITaskQueueService queueService,
                                       [NotNull] Expression <Func <T, Func <QueuedTaskExecutionContext, Task> > > expression)
            where T : class
        {
            Check.NotNull(queueService, nameof(queueService));
            Check.NotNull(expression, nameof(expression));

            // Retrieve the real expression
            var exp = expression.Body;

            if (exp is UnaryExpression unaryExpression)
            {
                exp = unaryExpression.Operand;
            }

            // Determine whether the expression body is null
            if (exp is ConstantExpression constantExpression && constantExpression.Value == null)
            {
                throw new ArgumentException(
                          "The body of the expression must be a method call or member access, instead got null.",
                          nameof(expression)
                          );
            }

            // Enqueue the task
            switch (exp)
            {
            case MemberExpression memberExpression:
                if (memberExpression.Member is PropertyInfo propertyInfo && propertyInfo.GetMethod != null &&
                    propertyInfo.GetMethod.IsStatic)
                {
                    queueService.Enqueue(new StaticMemberAccessQueueableTask(memberExpression.Member));
                    return;
                }

                queueService.Enqueue(new CompiledExpressionQueueableTask <T>(expression.Compile()));
                break;

            case MethodCallExpression methodCallExpression:
                if (methodCallExpression.Object is ConstantExpression methodConstantExpression &&
                    methodConstantExpression.Value is MethodInfo methodInfo &&
                    methodInfo.IsStatic)
                {
                    // The method call is to a static method, no need to compile the expression
                    queueService.Enqueue(new StaticMethodInvokationQueueableTask(methodInfo));
                    return;
                }

                queueService.Enqueue(new CompiledExpressionQueueableTask <T>(expression.Compile()));
                break;

            default:
                throw new ArgumentException(
                          $"The expression of '{expression.GetType().FullName}' is not supported.",
                          nameof(expression)
                          );
            }
        }
Beispiel #5
0
 public MoviesIndexerService(ILogger <MoviesIndexerService> logger, ILoggerFactory loggerFactory, IHttpClientFactory httpClientFactory, ITaskQueueService taskQueueService, INoSqlService noSqlService)
 {
     _logger           = logger;
     _loggerFactory    = loggerFactory;
     HttpClientFactory = httpClientFactory;
     _taskQueueService = taskQueueService;
     _noSqlConnector   = noSqlService.GetNoSqlConnector("mongo_db");
     _noSqlConnector.Configure("mongodb://localhost:27017/movies_db");
 }
Beispiel #6
0
        public Altadefinizione01Indexer(ILogger logger, IMoviesIndexerService moviesIndexerService, ITaskQueueService taskQueueService)
        {
            _logger = logger;
            _moviesIndexerService = moviesIndexerService;
            _taskQueueService     = taskQueueService;
            var attr = GetType().GetCustomAttribute <MoviesIndexerAttribute>();

            _httpClient = moviesIndexerService.HttpClientFactory.CreateClient("linkDownloader");
            _baseUrl    = attr.BaseUrl;
        }
Beispiel #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TaskQueueHostedService"/> class.
        /// </summary>
        /// <param name="serviceScopeFactory"></param>
        /// <param name="taskQueueService"></param>
        /// <param name="taskExceptionHandler"></param>
        /// <param name="logger"></param>
        public TaskQueueHostedService(
            [NotNull] IServiceScopeFactory serviceScopeFactory,
            [NotNull] ITaskQueueService taskQueueService,
            [NotNull] ITaskExceptionHandler taskExceptionHandler,
            [NotNull] ILogger <TaskQueueHostedService> logger)
        {
            Check.NotNull(serviceScopeFactory, nameof(serviceScopeFactory));
            Check.NotNull(taskQueueService, nameof(taskQueueService));
            Check.NotNull(taskExceptionHandler, nameof(taskExceptionHandler));
            Check.NotNull(logger, nameof(logger));

            _serviceScopeFactory  = serviceScopeFactory;
            _taskQueueService     = taskQueueService;
            _taskExceptionHandler = taskExceptionHandler;
            _logger = logger;
        }
Beispiel #8
0
 public TaskQueueHandleResult(TaskContext context, ITaskQueueService TaskQueueService)
 {
     Context           = context;
     _TaskQueueService = TaskQueueService;
 }