private static async Task <int> RunAsync(Action <IServiceCollection, IConfiguration> configure, Action <IConsumerHandler> addConsumers) { var config = Configuration.GetConfiguration(); LogHelper.Logger = new SerilogLogger(); try { LogHelper.Info("Starting Consumer..."); var services = new ServiceCollection(); Bootstrapper.RegisterServices(services, config, (s, c) => { s.AddScoped <IConsumerHandler, ConsumerHandler>(); }); configure(services, config); var provider = services.BuildServiceProvider(); var manager = provider.GetRequiredService <IConsumerHandler>(); addConsumers(manager); await manager.StartAsync(); LogHelper.Info("Exiting Consumer..."); return(0); } catch (Exception ex) { LogHelper.Error("Consumer terminated unexpectedly.", ex); #if DEBUG Console.ReadLine(); #endif return(1); } finally { PromptHelper.Wait(); } }
private static async Task <int> RunAsync(Action <IServiceCollection, IConfiguration> configure, Action <IScheduler> addJobs) { var config = Configuration.GetConfiguration(); LogHelper.Logger = new SerilogLogger(); try { LogHelper.Info("Starting QuartzJob..."); var services = new ServiceCollection(); Bootstrapper.RegisterServices(services, config); configure(services, config); var factory = new StdSchedulerFactory(); var scheduler = await factory.GetScheduler(); scheduler.JobFactory = new JobFactory(services.BuildServiceProvider()); configure(services, config); addJobs(scheduler); await scheduler.Start(); LogHelper.Info($"Exiting QuartzJob..."); return(0); } catch (Exception ex) { LogHelper.Error("QuartzJob terminated unexpectedly.", ex); return(1); } finally { LogHelper.Info($"While..."); PromptHelper.Wait(); } }
private static async Task <int> RunAsync(Action <IServiceCollection, IConfiguration> configure, Func <IServiceProvider, Task> execute) { var config = Config.Configuration.GetConfiguration(); LogHelper.Logger = new SerilogLogger(); try { LogHelper.Info($"Starting Console..."); var services = new ServiceCollection(); Bootstrapper.RegisterServices(services, config); configure(services, config); var provider = services.BuildServiceProvider(); await execute(provider); return(0); } catch (Exception ex) { LogHelper.Error($"Console terminated unexpectedly.", ex); #if DEBUG Console.ReadLine(); #endif return(1); } finally { PromptHelper.Wait(); LogHelper.Info($"Exiting Console..."); } }