public static JobsOptions UseSqlServer(this JobsOptions options, string connectionString)
 {
     return(options.UseSqlServer(opts =>
     {
         opts.ConnectionString = connectionString;
     }));
 }
        public DelayedJobProcessorTest()
        {
            _options = new JobsOptions()
            {
                PollingDelay = 0
            };
            _mockStateChanger       = new Mock <IStateChanger>();
            _mockStorage            = new Mock <IStorage>();
            _mockStorageConnection  = new Mock <IStorageConnection>();
            _mockStorageTransaction = new Mock <IStorageTransaction>();
            _mockStorageConnection.Setup(m => m.CreateTransaction()).Returns(_mockStorageTransaction.Object);
            _cancellationTokenSource = new CancellationTokenSource();

            var services = new ServiceCollection();

            services.AddTransient <DelayedJobProcessor>();
            services.AddLogging();
            services.AddSingleton(_options);
            services.AddSingleton(_mockStorage.Object);
            services.AddSingleton(_mockStorageConnection.Object);
            services.AddSingleton(_mockStateChanger.Object);
            services.AddTransient <IJobFactory, JobFactory>();
            services.AddTransient <NoRetryJob>();
            _provider = services.BuildServiceProvider();

            _context = new ProcessingContext(_provider, _mockStorage.Object, null, _cancellationTokenSource.Token);
        }
 /// <summary>
 /// Registers the cron jobs registries within the assembly
 /// </summary>
 /// <param name="assemblies">Assembly containing classes extending from <see cref="CronJobRegistry"/>.</param>
 public static void UseCronJobRegistries(this JobsOptions jobsOptions, IEnumerable <Assembly> assemblies)
 {
     foreach (var assembly in assemblies)
     {
         jobsOptions.UseCronJobRegistries(assembly);
     }
 }
        public static JobsOptions UseSqlServer(this JobsOptions options, Action <SqlServerOptions> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            options.RegisterExtension(new SqlServerJobsOptionsExtension(configure));

            return(options);
        }
        /// <summary>
        /// Registers the cron jobs registries within the assembly
        /// </summary>
        /// <param name="assembly">Assembly containing classes extending from <see cref="CronJobRegistry"/>.</param>
        public static void UseCronJobRegistries(this JobsOptions jobsOptions, Assembly assembly)
        {
            // Get all classes extending cron job registry
            var types = assembly.GetTypes().Where(type => typeof(CronJobRegistry).IsAssignableFrom(type));

            foreach (var type in types)
            {
                var registry = Activator.CreateInstance(type) as CronJobRegistry;
                jobsOptions.UseCronJobRegistry(registry);
            }
        }
        public DelayedJobProcessor(
            ILogger <DelayedJobProcessor> logger,
            JobsOptions options,
            IStateChanger stateChanger,
            IServiceProvider provider)
        {
            _logger       = logger;
            _options      = options;
            _stateChanger = stateChanger;
            _provider     = provider;

            _pollingDelay = TimeSpan.FromSeconds(_options.PollingDelay);
        }
示例#7
0
 public ProcessingServer(
     ILogger <ProcessingServer> logger,
     ILoggerFactory loggerFactory,
     IServiceProvider provider,
     IStorage storage,
     JobsOptions options)
 {
     _logger        = logger;
     _loggerFactory = loggerFactory;
     _provider      = provider;
     _storage       = storage;
     _options       = options;
     _cts           = new CancellationTokenSource();
 }
示例#8
0
        public static void AddJobs(
            this IServiceCollection services,
            Action <JobsOptions> configure)
        {
            services.AddScoped <IJobsManager, JobsManager>();
            services.AddSingleton <IJobFactory, JobFactory>();
            services.AddSingleton <IProcessingServer, ProcessingServer>();
            services.AddSingleton <IStateChanger, StateChanger>();

            // Processors
            services.AddTransient <DelayedJobProcessor>();
            services.AddTransient <CronJobProcessor>();
            services.AddTransient <JobQueuer>();

            var options = new JobsOptions();

            configure(options);
            options.Extension?.AddServices(services);
            services.AddSingleton(options);
        }