示例#1
0
        public void Configure(IWorkerApplicationBuilder app, IWorkerHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            // get the right section
            var configSection = Configuration.GetSection("DemoAccount");
            var queueConfig1  = new AzureQueueClientPriorityConfiguration(configSection.GetValue <string>("Queue"), 1, configSection.GetValue <string>("Account"), configSection.GetValue <string>("Key"));
            var queueConfig2  = new AzureQueueClientPriorityConfiguration(configSection.GetValue <string>("Queue1"), 2, configSection.GetValue <string>("Account"), configSection.GetValue <string>("Key"));

            // Use our middle ware which checks the queue for a new task
            app.UseStorageQueueProcessor(loggerFactory, new List <AzureQueueClientPriorityConfiguration>()
            {
                queueConfig1, queueConfig2
            }, async(operation, message, next) => {
                // get a logger
                var logger = loggerFactory.CreateLogger("Processor");

                // log the message
                logger.LogInformation("Received Message: {0}", message);

                // delay
                Thread.Sleep(5000);

                // jump to the next middleware
                await next.Invoke();
            });

            // When executing this middleware we are skipping the polling because we don't wnat to wait. This works
            // well together witht he job queue message processor which skips all middle ware execution when
            // no job is arrived
            app.UseSkipPollingMiddleware(loggerFactory);
        }
示例#2
0
        public Startup(IWorkerHostingEnvironment env)
        {
            // build the rest
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ProcessRootPath)
                          .AddEnvironmentVariables();

            Configuration = builder.Build();
        }
示例#3
0
        public Startup(IWorkerHostingEnvironment env)
        {
            // build the rest
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ProcessRootPath)
                          .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                          .AddJsonFile($"appsettings.demo.json", optional: true)
                          .AddEnvironmentVariables();

            Configuration = builder.Build();
        }
示例#4
0
        public void Configure(IWorkerApplicationBuilder app, IWorkerHostingEnvironment env, ILoggerFactory loggerFactory, IShutdownNotificationService shutdownService, IPollingService pollingService, ITimeoutService timeoutService)
        {
            shutdownService.OnShutdownNotification(async() =>
            {
                // get a logger
                var logger = loggerFactory.CreateLogger("ShutdownHandler");

                // delay
                logger.LogInformation("Delaying shutdown by 10 seconds");
                await Task.Delay(5000);

                // done
                logger.LogInformation("Finished delay");
            });

            app.Use((WorkerApplicationOperation operation, IWorkerApplicationMiddlewareExecutionController next) =>
            {
                // get a logger
                var logger = loggerFactory.CreateLogger("Processor");

                // lookup a scoped service
                var scopedService = operation.Services.GetService <IScopedService>();

                // log the message
                logger.LogInformation("MW01 - InstanceId: {0}", scopedService.InstanceId);

                return(next.Invoke());
            });

            app.Use((WorkerApplicationOperation operation, IWorkerApplicationMiddlewareExecutionController next) =>
            {
                // get a logger
                var logger = loggerFactory.CreateLogger("Processor");

                // lookup a scoped service
                var scopedService = operation.Services.GetService <IScopedService>();

                // log the message
                logger.LogInformation("MW02 - InstanceId: {0}", scopedService.InstanceId);

                return(next.Invoke());
            });

            /*app.Use((WorkerApplicationOperation operation, IWorkerApplicationMiddlewareExecutionController next) =>
             * {
             * // get a logger
             * var logger = loggerFactory.CreateLogger("AbortNextPolling");
             *
             * logger.LogInformation("Abort...");
             * pollingService.AbortDuringNextPolling();
             *
             * return next.Invoke();
             * });*/

            app.Use(async(WorkerApplicationOperation operation, IWorkerApplicationMiddlewareExecutionController next) =>
            {
                // get a logger
                var logger = loggerFactory.CreateLogger("Processor");
                logger.LogInformation("Delaying Job");

                // delay
                logger.LogInformation($"Delay 5sec - {DateTime.Now}");
                await Task.Delay(5000);

                // reset the timeout
                await timeoutService.ResetExecutionTimeout();

                // delay
                logger.LogInformation($"Delay 5sec - {DateTime.Now}");
                await Task.Delay(5000);

                // reset the timeout
                await timeoutService.ResetExecutionTimeout();

                // delay
                logger.LogInformation($"Delay 5sec - {DateTime.Now}");
                await Task.Delay(5000);

                // reset the timeout
                await timeoutService.ResetExecutionTimeout();

                // delay
                logger.LogInformation($"Delay 5sec - {DateTime.Now}");
                await Task.Delay(5000);

                // delay
                logger.LogInformation($"Delay 5sec - {DateTime.Now}");
                await Task.Delay(5000);

                // delay
                logger.LogInformation($"Delay 5sec - {DateTime.Now}");
                await Task.Delay(5000);

                // next
                await next.Invoke();
            });

            app.UseOnTimeout(async(WorkerApplicationOperation operation) =>
            {
                Console.WriteLine("Timeout Exceeded");
                await Task.CompletedTask;

                // abort
                Console.WriteLine("Aborting Worker");
                pollingService.AbortDuringNextPolling();
            });
        }