Exemplo n.º 1
0
        /// <summary>
        /// Specifies that the configured job will be triggered by an item inserted to the a queue.
        /// </summary>
        /// <param name="builder">The <see cref="TaskTriggerBuilder"/> used to configure the way that a job is triggered.</param>
        /// <param name="queueStoreTypeImplementation">CLR type of the implementation of an <see cref="IMessageQueue{T}"/></param>
        /// <param name="configureAction">The delegate used to configure the queue options.</param>
        /// <returns>The <see cref="WorkerHostBuilder"/> used to configure the worker host.</returns>
        private static WorkerHostBuilderForQueue WithQueueTrigger <TWorkItem>(this TaskTriggerBuilder builder, Type queueStoreTypeImplementation, Action <QueueOptions> configureAction = null) where TWorkItem : class
        {
            var options = new QueueOptions(builder.Services);

            configureAction?.Invoke(options);
            options.Services.AddTransient(builder.JobHandlerType);
            options.Services.AddTransient(typeof(IQueueNameResolver <TWorkItem>), sp => Activator.CreateInstance(typeof(DefaultQueueNameResolver <TWorkItem>), new object[] { options }));
            options.Services.AddTransient(typeof(IMessageQueue <TWorkItem>), queueStoreTypeImplementation);
            var queueStoreTypeDefault = builder.Options.QueueStoreType.MakeGenericType(typeof(TWorkItem));

            if (!queueStoreTypeDefault.Equals(queueStoreTypeImplementation))
            {
                options.Services.AddTransient(queueStoreTypeDefault);
            }
            options.Services.AddTransient(typeof(DequeueJob <TWorkItem>));
            options.Services.AddTransient(typeof(DequeuedCleanupJob <TWorkItem>));
            options.Services.AddTransient(serviceProvider => new DequeueJobSettings(
                                              jobHandlerType: builder.JobHandlerType,
                                              workItemType: typeof(TWorkItem),
                                              jobName: serviceProvider.GetService <IQueueNameResolver <TWorkItem> >().Resolve(),
                                              pollingInterval: options.PollingInterval,
                                              backoffThreshold: options.MaxPollingInterval,
                                              cleanUpInterval: options.CleanUpInterval,
                                              cleanUpBatchSize: options.CleanUpBatchSize,
                                              instanceCount: options.InstanceCount
                                              ));
            return(new WorkerHostBuilderForQueue(options.Services, builder.Options, typeof(TWorkItem)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Specifies that the configured job will be triggered by an item inserted to the a queue.
        /// </summary>
        /// <typeparam name="TState">The type of the persisted job state. This is a DTO to share state between every execution</typeparam>
        /// <param name="builder">The <see cref="TaskTriggerBuilder"/> used to configure the way that a job is triggered.</param>
        /// <param name="cronExpression">Cron expression</param>
        /// <param name="configureAction">The delegate used to configure the queue options.</param>
        /// <returns>The <see cref="WorkerHostBuilder"/> used to configure the worker host.</returns>
        public static WorkerHostBuilder WithScheduleTrigger <TState>(this TaskTriggerBuilder builder, string cronExpression, Action <ScheduleOptions> configureAction = null) where TState : class
        {
            if (string.IsNullOrWhiteSpace(cronExpression))
            {
                throw new ArgumentException($"'{nameof(cronExpression)}' cannot be null or whitespace", nameof(cronExpression));
            }
            var options = new ScheduleOptions(builder.Services)
            {
                CronExpression = cronExpression
            };

            configureAction?.Invoke(options);
            options.Services.AddTransient(builder.JobHandlerType);
            options.Services.AddTransient(typeof(IScheduledTaskStore <TState>), builder.Options.ScheduledTaskStoreType.MakeGenericType(typeof(TState)));
            options.Services.AddTransient(typeof(ScheduledJob <,>).MakeGenericType(builder.JobHandlerType, typeof(TState)));
            options.Services.AddTransient(serviceProvider => new ScheduledJobSettings(builder.JobHandlerType, typeof(TState), cronExpression, options.Name, options.Group, options.Description));
            return(new WorkerHostBuilder(options.Services, builder.Options));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Specifies that the configured job will be triggered by an item inserted to the a queue.
 /// </summary>
 /// <param name="builder">The <see cref="TaskTriggerBuilder"/> used to configure the way that a job is triggered.</param>
 /// <param name="cronExpression">Cron expression</param>
 /// <param name="configureAction">The delegate used to configure the queue options.</param>
 /// <returns>The <see cref="WorkerHostBuilder"/> used to configure the worker host.</returns>
 public static WorkerHostBuilder WithScheduleTrigger(this TaskTriggerBuilder builder, string cronExpression, Action <ScheduleOptions> configureAction = null) =>
 WithScheduleTrigger <Dictionary <string, object> >(builder, cronExpression, configureAction);
Exemplo n.º 4
0
 /// <summary>
 /// Specifies that the configured job will be triggered by an item inserted to the a queue.
 /// </summary>
 /// <typeparam name="TWorkItem"></typeparam>
 /// <param name="builder">The <see cref="TaskTriggerBuilder"/> used to configure the way that a job is triggered.</param>
 /// <param name="queueName">The name of the queue.</param>
 /// <param name="pollingIntervalInSeconds">Specifies the time interval between two attempts to dequeue new items.</param>
 /// <returns>The <see cref="WorkerHostBuilder"/> used to configure the worker host.</returns>
 public static WorkerHostBuilder WithQueueTrigger <TWorkItem>(this TaskTriggerBuilder builder, string queueName, int pollingIntervalInSeconds) where TWorkItem : class =>
 builder.WithQueueTrigger <TWorkItem>(options => new QueueOptions(builder.Services)
 {
     QueueName       = queueName,
     PollingInterval = pollingIntervalInSeconds
 });
Exemplo n.º 5
0
 /// <summary>
 /// Specifies that the configured job will be triggered by an item inserted to the a queue.
 /// </summary>
 /// <param name="builder">The <see cref="TaskTriggerBuilder"/> used to configure the way that a job is triggered.</param>
 /// <param name="configureAction">The delegate used to configure the queue options.</param>
 /// <returns>The <see cref="WorkerHostBuilder"/> used to configure the worker host.</returns>
 public static WorkerHostBuilderForQueue WithQueueTrigger <TWorkItem, TQueueStore>(this TaskTriggerBuilder builder, Action <QueueOptions> configureAction = null) where TWorkItem : class =>
 WithQueueTrigger <TWorkItem>(builder, typeof(TQueueStore), configureAction);
Exemplo n.º 6
0
 /// <summary>
 /// Specifies that the configured job will be triggered by an item inserted to the a queue.
 /// </summary>
 /// <param name="builder">The <see cref="TaskTriggerBuilder"/> used to configure the way that a job is triggered.</param>
 /// <param name="configureAction">The delegate used to configure the queue options.</param>
 /// <returns>The <see cref="WorkerHostBuilder"/> used to configure the worker host.</returns>
 public static WorkerHostBuilderForQueue WithQueueTrigger <TWorkItem>(this TaskTriggerBuilder builder, Action <QueueOptions> configureAction = null) where TWorkItem : class =>
 WithQueueTrigger <TWorkItem>(builder, builder.Options.QueueStoreType.MakeGenericType(typeof(TWorkItem)), configureAction);