/// <summary> /// Use SQS for the queue infrastructure /// </summary> /// <param name="builder">The QuidjiboBuilder.</param> /// <param name="sqsQuidjiboConfiguration">The configuration.</param> /// <returns></returns> public static QuidjiboBuilder UseSqs(this QuidjiboBuilder builder, Action <SqsQuidjiboConfiguration> sqsQuidjiboConfiguration) { var config = new SqsQuidjiboConfiguration(); sqsQuidjiboConfiguration(config); return(builder.UseSqs(config)); }
/// <summary> /// Use Sql Server for Work, Progress, and Scheduled Jobs, and sets Quidjibo configuration /// </summary> /// <param name="builder"></param> /// <param name="config"></param> /// <returns></returns> public static QuidjiboBuilder UseSqlServer(this QuidjiboBuilder builder, SqlServerQuidjiboConfiguration config) { return(builder.Configure(config) .ConfigureWorkProviderFactory(new SqlWorkProviderFactory(config.ConnectionString)) .ConfigureProgressProviderFactory(new SqlProgressProviderFactory(config.ConnectionString)) .ConfigureScheduleProviderFactory(new SqlScheduleProviderFactory(config.ConnectionString))); }
public static IApplicationBuilder UseQuidjibo(this IApplicationBuilder app, Action <QuidjiboBuilder> builder) { var quidjiboBuilder = new QuidjiboBuilder(); builder?.Invoke(quidjiboBuilder); return(app.UseQuidjibo(quidjiboBuilder)); }
/// <summary> /// Use WebProxy for Work, Progress, and Scheduled Jobs, and sets Quidjibo configuration /// </summary> /// <param name="builder"></param> /// <param name="config"></param> /// <returns></returns> public static QuidjiboBuilder UseWebProxyServer(this QuidjiboBuilder builder, WebProxyQuidjiboConfiguration config) { var client = new WebProxyClient(config.Url, config.ClientId, config.ClientSecret); return(builder.Configure(config) .ConfigureWorkProviderFactory(new WebProxyWorkProviderFactory(builder.LoggerFactory, client)) .ConfigureProgressProviderFactory(new WebProxyProgressProviderFactory(builder.LoggerFactory, client)) .ConfigureScheduleProviderFactory(new WebProxyScheduleProviderFactory(builder.LoggerFactory, client))); }
public void BuilderRequiresScheduleProviderFactory() { var quidjibo = new QuidjiboBuilder(); Action build = () => quidjibo.ConfigureAssemblies(GetType().Assembly).ConfigureScheduleProviderFactory(null).BuildServer(); build.Should().Throw <QuidjiboBuilderException>() .WithMessage("Failed to validate. See list of errors for more detail.") .And.Errors.Should().Contain("Requires Schedule Provider Factory"); }
public void BuilderRequiresProgressProviderFactory() { var quidjibo = new QuidjiboBuilder(); Action build = () => quidjibo.BuildServer(); build.Should().Throw <QuidjiboBuilderException>() .WithMessage("Failed to validate. See list of errors for more detail.") .And.Errors.Should().Contain("Requires Progress WorkProvider Factory"); }
public static IAppBuilder UseQuidjibo(this IAppBuilder appBuilder, QuidjiboBuilder quidjiboBuilder) { var props = new AppProperties(appBuilder.Properties); var server = quidjiboBuilder.BuildServer(); quidjiboBuilder.BuildClient(); props.OnAppDisposing.Register(server.Dispose); server.Start(); return(appBuilder); }
public static IApplicationBuilder UseQuidjibo(this IApplicationBuilder app, QuidjiboBuilder builder) { var lifetime = app.ApplicationServices.GetRequiredService <IApplicationLifetime>(); var server = builder.BuildServer(); builder.BuildClient(); lifetime.ApplicationStarted.Register(server.Start); lifetime.ApplicationStopping.Register(server.Stop); lifetime.ApplicationStopped.Register(server.Dispose); return(app); }
static async Task Main(string[] args) { System.Console.WriteLine("Resgrid Worker Engine (Events)"); System.Console.WriteLine("-----------------------------------------"); LoadConfiguration(args); Prime(); var aes = Aes.Create(); var key = string.Join(",", aes.Key); var cts = new CancellationTokenSource(); var cancellationToken = cts.Token; System.Console.CancelKeyPress += (s, e) => { cts.Cancel(); }; var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole()); var logger = loggerFactory.CreateLogger <Program>(); // Setup DI var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule(new QuidjiboModule(typeof(Program).Assembly)); containerBuilder.RegisterInstance <ILogger>(logger); var container = containerBuilder.Build(); // Setup Quidjibo var quidjiboBuilder = new QuidjiboBuilder() .ConfigureLogging(loggerFactory) .UseAutofac(container) .UseAes(Encoding.ASCII.GetBytes(WorkerConfig.PayloadKey)) .UseSqlServer(WorkerConfig.WorkerDbConnectionString) .ConfigurePipeline(pipeline => pipeline.UseDefault()); // Quidjibo Client var client = quidjiboBuilder.BuildClient(); // Long Running Jobs await client.PublishAsync(new SystemQueueProcessorCommand(50), cancellationToken); await client.PublishAsync(new QueuesProcessorCommand(51), cancellationToken); // Quidjibo Server using (var workServer = quidjiboBuilder.BuildServer()) { // Start Quidjibo workServer.Start(); cancellationToken.WaitHandle.WaitOne(); } System.Console.ReadLine(); }
private static async Task MainAsync(string[] args, CancellationToken cancellationToken) { var loggerFactory = new LoggerFactory().AddConsole(LogLevel.Debug); var logger = loggerFactory.CreateLogger <Program>(); logger.LogDebug("Hello Quidjibo!"); // Setup DI var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule(new QuidjiboModule(typeof(Program).Assembly)); containerBuilder.RegisterType <SimpleService>().As <ISimpleService>(); var container = containerBuilder.Build(); // Setup Quidjibo var quidjiboBuilder = new QuidjiboBuilder() .ConfigureLogging(loggerFactory) //.ConfigureAssemblies(typeof(Program).GetTypeInfo().Assembly) .UseAutofac(container) .UseAes(fakeAesKey) .UseSqlServer("Server=localhost;Database=SampleDb;Trusted_Connection=True;") .ConfigurePipeline(pipeline => pipeline.UseDefault()); // Quidjibo Client var client = quidjiboBuilder.BuildClient(); var count = 10; var list = new List <Task>(count); var stopWatch = new Stopwatch(); stopWatch.Start(); for (var j = 0; j < count; j++) { list.Add(client.PublishAsync(new Job.Command(j), cancellationToken)); } await Task.WhenAll(list); list.Clear(); stopWatch.Stop(); Console.WriteLine("Published {0} items in {1}s", count, stopWatch.Elapsed.TotalSeconds); // Quidjibo Server using (var workServer = quidjiboBuilder.BuildServer()) { // Start Quidjibo workServer.Start(); cancellationToken.WaitHandle.WaitOne(); } }
public void When_Builder_IsNotConfigured_ShouldUseDefaults() { var quidjibo = new QuidjiboBuilder() .Configure(Substitute.For <IQuidjiboConfiguration>()) .ConfigureWorkProviderFactory(Substitute.For <IWorkProviderFactory>()) .ConfigureScheduleProviderFactory(Substitute.For <IScheduleProviderFactory>()) .ConfigureProgressProviderFactory(Substitute.For <IProgressProviderFactory>()); var server = quidjibo.BuildServer(); var client = quidjibo.BuildClient(); server.Should().NotBeNull(); client.Should().NotBeNull(); }
/// <summary> /// Use Sql Server for Work, Progress, and Scheduled Jobs /// </summary> /// <param name="builder"></param> /// <param name="connectionString"></param> /// <param name="queues"></param> /// <returns></returns> public static QuidjiboBuilder UseSqlServer(this QuidjiboBuilder builder, string connectionString, params string[] queues) { if (queues == null || queues.Length == 0) { queues = new[] { "default" }; } var config = new SqlServerQuidjiboConfiguration { ConnectionString = connectionString, Queues = queues }; return(builder.Configure(config) .ConfigureWorkProviderFactory(new SqlWorkProviderFactory(connectionString)) .ConfigureProgressProviderFactory(new SqlProgressProviderFactory(connectionString)) .ConfigureScheduleProviderFactory(new SqlScheduleProviderFactory(connectionString))); }
/// <summary> /// Use Sql Server For Work /// </summary> /// <param name="builder"></param> /// <param name="sqlServerQuidjiboConfiguration"></param> /// <returns></returns> public static QuidjiboBuilder UseSqlServerForWork(this QuidjiboBuilder builder, SqlServerQuidjiboConfiguration sqlServerQuidjiboConfiguration) { return(builder.ConfigureWorkProviderFactory(new SqlWorkProviderFactory(builder.LoggerFactory, sqlServerQuidjiboConfiguration))); }
private static async Task MainAsync(string[] args, CancellationToken cancellationToken) { var loggerFactory = new LoggerFactory().AddConsole(LogLevel.Debug); var logger = loggerFactory.CreateLogger <Program>(); // Setup DI var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule(new QuidjiboModule(typeof(Program).Assembly)); containerBuilder.RegisterInstance <ILogger>(logger); var container = containerBuilder.Build(); // Setup Quidjibo var quidjiboBuilder = new QuidjiboBuilder() .ConfigureLogging(loggerFactory) .UseAutofac(container) .UseAes(Encoding.ASCII.GetBytes(WorkerConfig.PayloadKey)) .UseSqlServer(WorkerConfig.WorkerDbConnectionString) .ConfigurePipeline(pipeline => pipeline.UseDefault()); // Quidjibo Client var client = quidjiboBuilder.BuildClient(); // Long Running Jobs await client.PublishAsync(new SystemQueueProcessorCommand(8), cancellationToken); await client.PublishAsync(new QueuesProcessorCommand(4), cancellationToken); // Scheduled Jobs await client.ScheduleAsync("Calendar Notifications", new CalendarNotificationCommand(1), Cron.MinuteIntervals(20), cancellationToken); await client.ScheduleAsync("Call Email Import", new CallEmailImportCommand(2), Cron.MinuteIntervals(5), cancellationToken); await client.ScheduleAsync("Call Pruning", new CallPruneCommand(3), Cron.MinuteIntervals(60), cancellationToken); await client.ScheduleAsync("Report Delivery", new ReportDeliveryTaskCommand(5), Cron.MinuteIntervals(60), cancellationToken); await client.ScheduleAsync("Shift Notifier", new ShiftNotiferCommand(6), Cron.MinuteIntervals(60), cancellationToken); await client.ScheduleAsync("Staffing Schedule", new Commands.StaffingScheduleCommand(7), Cron.MinuteIntervals(15), cancellationToken); await client.ScheduleAsync("Training Notifier", new TrainingNotiferCommand(9), Cron.MinuteIntervals(60), cancellationToken); // Quidjibo Server using (var workServer = quidjiboBuilder.BuildServer()) { // Start Quidjibo workServer.Start(); cancellationToken.WaitHandle.WaitOne(); } }
public static QuidjiboBuilder UseStructureMap(this QuidjiboBuilder builder, IContainer container) { return(builder.ConfigureResolver(new StructureMapDependencyResolver(container))); }
public static QuidjiboBuilder UseAutofac(this QuidjiboBuilder builder, ILifetimeScope lifetimeScope) { return(builder.ConfigureResolver(new AutofacDependencyResolver(lifetimeScope))); }
public static IAppBuilder UseQuidjiboProxyServer(this IAppBuilder appBuilder, QuidjiboBuilder quidjiboBuilder) { return(appBuilder); }
public static IApplicationBuilder UseQuidjiboWebProxy(this IApplicationBuilder app, QuidjiboBuilder quidjiboBuilder) { app.Map("/quidjibo", quidjibo => { quidjibo.Map("/progress-items", progress => { progress.MapWhen(x => x.Request.Method == HttpMethods.Get, get => get.Run(async context => { await ExecuteAsync <Guid>(context, async wrapper => { var factory = quidjiboBuilder.ProgressProviderFactory; var provider = await factory.CreateAsync(wrapper.Queues, context.RequestAborted); var data = await provider.LoadByCorrelationIdAsync(wrapper.Data, context.RequestAborted); await WriteAsync(context, data); }); })); progress.MapWhen(x => x.Request.Method == HttpMethods.Post, post => post.Run(async context => { await ExecuteAsync <ProgressItem>(context, async wrapper => { var factory = quidjiboBuilder.ProgressProviderFactory; var provider = await factory.CreateAsync(wrapper.Queues, context.RequestAborted); await provider.ReportAsync(wrapper.Data, context.RequestAborted); await WriteAsync(context); }); })); }); quidjibo.Map("/schedule-items", schedule => { schedule.Map("/receive", receive => receive.Run(async context => { await ExecuteAsync(context, async wrapper => { var factory = quidjiboBuilder.ScheduleProviderFactory; var provider = await factory.CreateAsync(wrapper.Queues, context.RequestAborted); var data = await provider.ReceiveAsync(context.RequestAborted); await WriteAsync(context, data); }); })); schedule.Map("/complete", receive => receive.Run(async context => { await ExecuteAsync <ScheduleItem>(context, async wrapper => { var factory = quidjiboBuilder.ScheduleProviderFactory; var provider = await factory.CreateAsync(wrapper.Queues, context.RequestAborted); await provider.CompleteAsync(wrapper.Data, context.RequestAborted); await WriteAsync(context); }); })); schedule.Map("/exists", receive => receive.Run(async context => { await ExecuteAsync <string>(context, async wrapper => { var factory = quidjiboBuilder.ScheduleProviderFactory; var provider = await factory.CreateAsync(wrapper.Queues, context.RequestAborted); var data = await provider.ExistsAsync(wrapper.Data, context.RequestAborted); await WriteAsync(context, data); }); })); schedule.Map("/delete", delete => delete.Run(async context => { await ExecuteAsync <Guid>(context, async wrapper => { var factory = quidjiboBuilder.ScheduleProviderFactory; var provider = await factory.CreateAsync(wrapper.Queues, context.RequestAborted); await provider.DeleteAsync(wrapper.Data, context.RequestAborted); await WriteAsync(context); }); })); schedule.MapWhen(x => x.Request.Method == HttpMethods.Get, load => load.Run(async context => { await ExecuteAsync <string>(context, async wrapper => { var factory = quidjiboBuilder.ScheduleProviderFactory; var provider = await factory.CreateAsync(wrapper.Queues, context.RequestAborted); var data = await provider.LoadByNameAsync(wrapper.Data, context.RequestAborted); await WriteAsync(context, data); }); })); schedule.MapWhen(x => x.Request.Method == HttpMethods.Post, create => create.Run(async context => { await ExecuteAsync <ScheduleItem>(context, async wrapper => { var factory = quidjiboBuilder.ScheduleProviderFactory; var provider = await factory.CreateAsync(wrapper.Queues, context.RequestAborted); await provider.CreateAsync(wrapper.Data, context.RequestAborted); await WriteAsync(context); }); })); }); quidjibo.Map("/work-items", workApp => { workApp.Map("/receive", receive => receive.Run(async context => { await ExecuteAsync <string>(context, async wrapper => { var factory = quidjiboBuilder.WorkProviderFactory; var provider = await factory.CreateAsync(wrapper.Queues, context.RequestAborted); var data = await provider.ReceiveAsync(wrapper.Data, context.RequestAborted); await WriteAsync(context, data); }); })); workApp.Map("/renew", renew => renew.Run(async context => { await ExecuteAsync <WorkItem>(context, async wrapper => { var factory = quidjiboBuilder.WorkProviderFactory; var provider = await factory.CreateAsync(wrapper.Queues, context.RequestAborted); var data = await provider.RenewAsync(wrapper.Data, context.RequestAborted); await WriteAsync(context, data); }); })); workApp.Map("/complete", complete => complete.Run(async context => { await ExecuteAsync <WorkItem>(context, async wrapper => { var factory = quidjiboBuilder.WorkProviderFactory; var provider = await factory.CreateAsync(wrapper.Queues, context.RequestAborted); await provider.CompleteAsync(wrapper.Data, context.RequestAborted); await WriteAsync(context); }); })); workApp.Map("/fault", fault => fault.Run(async context => { await ExecuteAsync <WorkItem>(context, async wrapper => { var factory = quidjiboBuilder.WorkProviderFactory; var provider = await factory.CreateAsync(wrapper.Queues, context.RequestAborted); await provider.FaultAsync(wrapper.Data, context.RequestAborted); await WriteAsync(context); }); })); workApp.MapWhen(x => x.Request.Method == HttpMethods.Post, send => send.Run(async context => { await ExecuteAsync <WorkItem>(context, async wrapper => { var factory = quidjiboBuilder.WorkProviderFactory; var provider = await factory.CreateAsync(wrapper.Queues, context.RequestAborted); await provider.SendAsync(wrapper.Data, 0, context.RequestAborted); await WriteAsync(context); }); })); }); }); return(app); }
public static QuidjiboBuilder UseSimpleInjector(this QuidjiboBuilder builder, Container container) { return(builder.ConfigureResolver(new SimpleInjectorDependencyResolver(container))); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { var aes = Aes.Create(); var key = string.Join(",", aes.Key); //System.Console.CancelKeyPress += (s, e) => { cancellationToken..Cancel(); }; _logger.Log(LogLevel.Information, "Starting Scheduler"); var loggerFactory = LoggerFactory.Create(builder => builder.AddConsole()); var logger = loggerFactory.CreateLogger <Program>(); // Setup DI var containerBuilder = new ContainerBuilder(); containerBuilder.RegisterModule(new QuidjiboModule(typeof(Program).Assembly)); containerBuilder.RegisterInstance <ILogger>(logger); var container = containerBuilder.Build(); // Setup Quidjibo var quidjiboBuilder = new QuidjiboBuilder() .ConfigureLogging(loggerFactory) .UseAutofac(container) .UseAes(Encoding.ASCII.GetBytes(WorkerConfig.PayloadKey)) .UseSqlServer(WorkerConfig.WorkerDbConnectionString) .ConfigurePipeline(pipeline => pipeline.UseDefault()); // Quidjibo Client var client = quidjiboBuilder.BuildClient(); _logger.Log(LogLevel.Information, "Scheduler Started"); //// Long Running Jobs ////await client.PublishAsync(new SystemQueueProcessorCommand(8), cancellationToken); ////await client.PublishAsync(new QueuesProcessorCommand(4), cancellationToken); var isEventsOnly = Environment.GetEnvironmentVariable("RESGRID__EVENTSONLY"); if (String.IsNullOrWhiteSpace(isEventsOnly) || isEventsOnly.ToLower() == "false") { _logger.Log(LogLevel.Information, "Starting Scheduled Jobs"); // Scheduled Jobs _logger.Log(LogLevel.Information, "Scheduling Calendar Notifications"); await client.ScheduleAsync("Calendar Notifications", new CalendarNotificationCommand(1), Cron.MinuteIntervals(20), stoppingToken); //System.Console.WriteLine("Scheduling Calendar Notifications"); //await client.ScheduleAsync("Call Email Import", // new CallEmailImportCommand(2), // Cron.MinuteIntervals(5), // cancellationToken); _logger.Log(LogLevel.Information, "Scheduling Call Pruning"); await client.ScheduleAsync("Call Pruning", new CallPruneCommand(3), Cron.MinuteIntervals(60), stoppingToken); _logger.Log(LogLevel.Information, "Scheduling Report Delivery"); await client.ScheduleAsync("Report Delivery", new ReportDeliveryTaskCommand(5), Cron.MinuteIntervals(14), stoppingToken); _logger.Log(LogLevel.Information, "Scheduling Shift Notifier"); await client.ScheduleAsync("Shift Notifier", new ShiftNotiferCommand(6), Cron.MinuteIntervals(720), stoppingToken); _logger.Log(LogLevel.Information, "Scheduling Staffing Schedule"); await client.ScheduleAsync("Staffing Schedule", new Commands.StaffingScheduleCommand(7), Cron.MinuteIntervals(5), stoppingToken); _logger.Log(LogLevel.Information, "Scheduling Training Notifier"); await client.ScheduleAsync("Training Notifier", new TrainingNotiferCommand(9), Cron.MinuteIntervals(30), stoppingToken); _logger.Log(LogLevel.Information, "Scheduling Status Schedule"); await client.ScheduleAsync("Status Schedule", new Commands.StatusScheduleCommand(11), Cron.MinuteIntervals(5), stoppingToken); } else { _logger.Log(LogLevel.Information, "Starting in Events Only Mode!"); } // Quidjibo Server using (var workServer = quidjiboBuilder.BuildServer()) { // Start Quidjibo workServer.Start(); stoppingToken.WaitHandle.WaitOne(); } //while (!cancellationToken.IsCancellationRequested) //{ // await Task.Delay(TimeSpan.FromSeconds(1)); //} }
/// <summary> /// Use Sql Server For Scheduled Jobs /// </summary> /// <param name="builder"></param> /// <param name="connectionString"></param> /// <returns></returns> public static QuidjiboBuilder UseSqlServerForSchedule(this QuidjiboBuilder builder, string connectionString) { return(builder.ConfigureScheduleProviderFactory(new SqlScheduleProviderFactory(connectionString))); }
public static QuidjiboBuilder UseAes(this QuidjiboBuilder builder, IKeyProvider keyProvider) { return(builder.ConfigureProtector(new AesPayloadProtector(keyProvider))); }
public static QuidjiboBuilder UseDependencyInjection(this QuidjiboBuilder builder, IServiceProvider serviceProvider) { return(builder.ConfigureResolver(new DependencyInjectionDependencyResolver(serviceProvider))); }
/// <summary> /// Use Sql Server For Progress /// </summary> /// <param name="builder"></param> /// <param name="connectionString"></param> /// <returns></returns> public static QuidjiboBuilder UseSqlServerForProgress(this QuidjiboBuilder builder, string connectionString) { return(builder.ConfigureProgressProviderFactory(new SqlProgressProviderFactory(builder.LoggerFactory, connectionString))); }
public static QuidjiboBuilder UseAes(this QuidjiboBuilder builder, byte[] aesKey) { return(builder.ConfigureProtector(new AesPayloadProtector(new KeyProvider(aesKey)))); }
/// <summary> /// Use SQS for the queue infrastructure /// </summary> /// <param name="builder">The QuidjiboBuilder.</param> /// <param name="sqsQuidjiboConfiguration">The configuration.</param> /// <returns></returns> public static QuidjiboBuilder UseSqs(this QuidjiboBuilder builder, SqsQuidjiboConfiguration sqsQuidjiboConfiguration) { return(builder.Configure(sqsQuidjiboConfiguration) .ConfigureWorkProviderFactory(new SqsWorkProviderFactory(builder.LoggerFactory, sqsQuidjiboConfiguration))); }