internal HangfireConsoleConfiguration(HangfireConfiguration hangfire) { if (hangfire == null) { throw new ArgumentNullException(nameof(hangfire)); } Hangfire = hangfire .Configuration((configuration, kernel) => { if (_options != null) { var options = new ConsoleOptions(); _options(options); configuration.UseConsole(options); } else { configuration.UseConsole(); } configuration .UseFilter(kernel.Resolve <SetPerformContextFilter>()); }); }
private static void mainLoop(HangfireConfiguration hangfireConfiguration) { Console.WriteLine("Started."); Console.WriteLine("'stop' to exit."); Console.WriteLine("'add 1' to queue a job."); while (true) { var command = Console.ReadLine(); if (command == null || command.Equals("stop", StringComparison.OrdinalIgnoreCase)) { break; } if (command.StartsWith("add", StringComparison.OrdinalIgnoreCase)) { try { var publisher = hangfireConfiguration.QueryPublishers().First(); var workCount = int.Parse(command.Substring(4)); for (var i = 0; i < workCount; i++) { var number = i; publisher.BackgroundJobClient.Enqueue <Services>(x => x.Random(number)); } Console.WriteLine("Jobs enqueued on " + publisher.ConfigurationId); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } }
public ConfigurationMiddleware( RequestDelegate next, IDictionary <string, object> properties) { var injected = properties?.ContainsKey("HangfireConfiguration") ?? false; if (injected) { _configuration = (HangfireConfiguration)properties["HangfireConfiguration"]; } else { _configuration = new HangfireConfiguration(); if (properties?.ContainsKey("HangfireConfigurationOptions") ?? false) { _configuration.UseOptions((ConfigurationOptions)properties["HangfireConfigurationOptions"]); } } _options = _configuration.Options().ConfigurationOptions(); _configurationApi = _configuration.ConfigurationApi(); if (_options.PrepareSchemaIfNecessary) { using (var c = _options.ConnectionString.CreateConnection()) HangfireConfigurationSchemaInstaller.Install(c); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ApplicationDbContext dataContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } // Hangfire HangfireConfiguration.Configure(app); app.UseLiveReload(); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => endpoints.MapRazorPages()); DatabaseConfiguration.Configure(dataContext); }
public WebServerUnderTest(HangfireConfiguration hangfireConfiguration, string urlPathMatch = null) { _urlPathMatch = urlPathMatch ?? "/config"; var(server, client) = createServer(hangfireConfiguration); _server = server; _client = client; }
public void ConfigureServices(IServiceCollection services) { SimpleInjectorConfiguration.ConfigureServices(services, _configuration); CorsConfiguration.ConfigureServices(services); MvcConfiguration.ConfigureServices(services); SwaggerConfiguration.ConfigureServices(services); HangfireConfiguration.ConfigureServices(services, _configuration); DatabaseConfiguration.ConfigureServices(services, _configuration); }
public DynamicHangfireDashboardsMiddleware( RequestDelegate next, ConfigurationOptions options, DashboardOptions dashboardOptions) { _next = next; _dashboardOptions = dashboardOptions; _configuration = new HangfireConfiguration(); _configuration.UseOptions(options); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { DatabaseConfiguration.Configure(app); LoggingConfiguration.Configure(app, _configuration, loggerFactory); RewriteConfiguration.Configure(app, env); SimpleInjectorConfiguration.Configure(app); CorsConfiguration.Configure(app, _configuration); MvcConfiguration.Configure(app, env); SwaggerConfiguration.Configure(app); AutoMapperConfiguration.Configure(); FluentValidationConfiguration.Configure(); HangfireConfiguration.Configure(app, _configuration); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Interface mapping InterfaceConfiguration.ConfigureServices(services); // Database DatabaseConfiguration.ConfigureServices(services, Configuration); // Hangfire HangfireConfiguration.ConfigureServices(services, Configuration); services.AddRazorPages() .AddRazorRuntimeCompilation(); services.AddLiveReload(); }
private (IDisposable server, HttpClient client) createServer(HangfireConfiguration hangfireConfiguration) { var server = new HostBuilder() .ConfigureWebHost(webHost => { webHost.UseTestServer(); webHost.Configure(app => { app.Properties.Add("HangfireConfiguration", hangfireConfiguration); app.UseHangfireConfigurationUI(_urlPathMatch, null); }); }) .StartAsync() .Result; return(server, server.GetTestClient()); }
public void ConfigurationIsLoadedCorrectly() { // arrange ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireEnabled, true.ToString()); ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireEnableDashboard, false.ToString()); var hangfireConfigDummy = new Mock <HangfireStorageConfigurationBase>(); var activatorDummy = new Mock <JobActivator>(); // act var sut = new HangfireConfiguration(new List <HangfireStorageConfigurationBase> { hangfireConfigDummy.Object }, activatorDummy.Object, new List <HangfireJobBase>()); // assert sut.Enabled.Should().BeTrue(); sut.EnableDashboard.Should().BeFalse(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.EnvironmentName == DevelopmentEnvironmentName) { app.UseDeveloperExceptionPage(); } else { app.UseDeveloperExceptionPage(); app.UseExceptionHandler("/Error"); app.UseHsts(); } // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); app.UseStaticFiles(); app.UseCookiePolicy(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapDefaultControllerRoute(); endpoints.MapAreaControllerRoute( "admin", "admin", "Admin/{controller=Home}/{action=Index}/{id?}"); }); app.ConfigureExceptionHandler(new ApplicationLoggerManager()); HangfireConfiguration.AddHangfire(app, env.EnvironmentName == DevelopmentEnvironmentName); }
public static IConfigure UsingHangfire(this IBackgroundJobConfiguration configuration, Action <IHangfireConfiguration> hangfireAction) { configuration.IsJobExecutionEnabled = true; var hangfireConfiguration = new HangfireConfiguration(); hangfireAction(hangfireConfiguration); var services = configuration.Configure.Services; services.AddSingleton <IHangfireConfiguration>(hangfireConfiguration); services.AddSingleton <IBackgroundJobManager, HangfireBackgroundJobManager>(); hangfireConfiguration.GlobalConfiguration.UseActivator(new HangfireIocJobActivator(services.BuildServiceProvider())); GlobalJobFilters.Filters.Add(services.BuildServiceProvider().GetService <HangfireJobExceptionFilter>()); return(configuration.Configure); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseSpaStaticFiles(); app.UseRouting(); app.UseSpa(spa => { spa.Options.SourcePath = "ClientApp"; }); app.UseEndpoints(endpoints => { endpoints.MapDefaultControllerRoute(); endpoints.MapControllerRoute( name: "default", pattern: "{controller}/{action=Index}/{id?}"); endpoints.MapHub <MessagingHub>("/messagingHub"); }); app.ConfigureExceptionHandler(new ApplicationLoggerManager()); HangfireConfiguration.AddHangfire(app, env.EnvironmentName == DevelopmentEnvironmentName); }
public void DisabledHangfireIsNoSetUp() { // arrange ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireEnabled, false.ToString()); ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireEnableDashboard, false.ToString()); var activatorDummy = new Mock <JobActivator>(); var hangfireConfigDummy = new HangfireStorageProviderFixture(); var appBuilderDummy = new AppBuilderFixture(); var sut = new HangfireConfiguration(new List <HangfireStorageConfigurationBase> { hangfireConfigDummy }, activatorDummy.Object, new List <HangfireJobBase>()); // act sut.SetupHangfire(appBuilderDummy); // assert hangfireConfigDummy.IsActive.Should().BeFalse(); }
public void JobsAreNotConfiguredIfHangfireIsNotUsed() { // arrange ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireEnabled, true.ToString()); ApplicationConfigurationHelper.AdjustKeys(ConfigurationKeys.HangfireEnableDashboard, false.ToString()); var activatorDummy = new Mock <JobActivator>(); var jobDummy = new JobFixture(); var hangfireConfigDummy = new HangfireStorageProviderFixture(); var appBuilderDummy = new AppBuilderFixture(); var sut = new HangfireConfiguration(new List <HangfireStorageConfigurationBase> { hangfireConfigDummy }, activatorDummy.Object, new List <HangfireJobBase> { jobDummy }); // act sut.SetupHangfire(appBuilderDummy); // assert jobDummy.WasSetUp.Should().BeTrue(); }
public void Configuration(IAppBuilder app) { HangfireConfiguration.HangfireInit("HangfireDb", app); }
public BasicDashboardAuthorizationFilter(HangfireConfiguration hangfireConfiguration) { _hangfireConfiguration = hangfireConfiguration; }
public override void ConfigureHangfire(TenantBuilderContext context, HangfireConfiguration configuration) { }
public ConfigurationPage(HangfireConfiguration configuration, string basePath, ConfigurationOptions options) { _viewModelBuilder = configuration.ViewModelBuilder(); _basePath = basePath; _options = options; }
public void Configure(IApplicationBuilder app) { GlobalConfiguration.Configuration .UseColouredConsoleLogProvider() .SetDataCompatibilityLevel(CompatibilityLevel.Version_170) .UseSimpleAssemblyNameTypeSerializer() .UseRecommendedSerializerSettings(); app.UseDeveloperExceptionPage(); var configurationConnectionString = @"Username=postgres;Password=root;Host=localhost;Database=""hangfire.sample"";"; var defaultHangfireConnectionString = @"Username=postgres;Password=root;Host=localhost;Database=""hangfire.sample"";"; var defaultHangfireSchema = "hangfirecustomschemaname"; app.Use((context, next) => { // simulate a hosting site with content security policy context.Response.Headers.Append("Content-Security-Policy", "script-src 'self'; frame-ancestors 'self';"); // simulate a hosting site with a static file handler if (context.Request.Path.Value.Split('/').Last().Contains(".")) { context.Response.StatusCode = (int)HttpStatusCode.NotFound; return(Task.CompletedTask); } return(next.Invoke()); }); var storageOptions = new PostgreSqlStorageOptions() { QueuePollInterval = TimeSpan.FromSeconds(2), PrepareSchemaIfNecessary = true, SchemaName = "NotUsedSchemaName" }; var options = new ConfigurationOptions { ConnectionString = configurationConnectionString, PrepareSchemaIfNecessary = true, UpdateConfigurations = new[] { new UpdateStorageConfiguration { ConnectionString = defaultHangfireConnectionString, Name = DefaultConfigurationName.Name(), SchemaName = defaultHangfireSchema } } }; Console.WriteLine(); Console.WriteLine(Program.NodeAddress + "/HangfireConfiguration"); app.UseHangfireConfigurationUI("/HangfireConfiguration", options); HangfireConfiguration = app .UseHangfireConfiguration(options) .UseStorageOptions(storageOptions) ; HangfireConfiguration .UseStorageOptions(storageOptions) //Needed???? already set above .UseServerOptions(new BackgroundJobServerOptions { Queues = new[] { "critical", "default" }, }) .StartPublishers() .StartWorkerServers(new[] { new CustomBackgroundProcess() }); HangfireConfiguration .QueryAllWorkerServers() .ForEach(x => { Console.WriteLine(Program.NodeAddress + $"/HangfireDashboard/{x.ConfigurationId}"); }); app.UseDynamicHangfireDashboards("/HangfireDashboard", options, new DashboardOptions()); }
public MessageManager(IMessageExecutor messageExecutor, IMediator mediator, IOptions <HangfireConfiguration> hangfireConfig) { _messageExecutor = messageExecutor; _mediator = mediator; _hangfireConfig = hangfireConfig.Value; }