コード例 #1
0
        static void Main()
        {
            CreateDemoData();

            JobHostConfiguration configuration = new JobHostConfiguration();

            // Demonstrates the global queue processing settings that can
            // be configured
            configuration.Queues.MaxPollingInterval = TimeSpan.FromSeconds(30);
            configuration.Queues.MaxDequeueCount = 10;
            configuration.Queues.BatchSize = 16;
            configuration.Queues.NewBatchThreshold = 20;

            // Demonstrates how queue processing can be customized further
            // by defining a custom QueueProcessor Factory
            configuration.Queues.QueueProcessorFactory = new CustomQueueProcessorFactory();

            JobHost host = new JobHost(configuration);
            host.Start();

            // Stop the host if Ctrl + C/Ctrl + Break is pressed
            Console.CancelKeyPress += (sender, args) =>
            {
                host.Stop();
            };

            while(true)
            {
                Thread.Sleep(500);
            }
        }
        private void InvokeQueueFunctionAndWaitForResult(MethodInfo function, CloudQueueMessage message = null)
        {
            if (message == null)
            {
                message = new CloudQueueMessage(POCO.JsonSample);
            }

            string queueName = CreateQueueName(function, input: true);

            CloudQueueClient queueClient = StorageAccount.CloudStorageAccount.CreateCloudQueueClient();
            CloudQueue queue = queueClient.GetQueueReference(queueName);
            queue.CreateIfNotExists();
            queue.AddMessage(message);

            JobHostConfiguration hostConfiguration = new JobHostConfiguration(StorageAccount.ConnectionString)
            {
                TypeLocator = new ExplicitTypeLocator(
                    typeof(QueueArgumentsDisplayFunctions),
                    typeof(DoneNotificationFunction))
            };

            using (JobHost host = new JobHost(hostConfiguration))
            using (DoneNotificationFunction._doneEvent = new ManualResetEvent(initialState: false))
            {
                host.Start();
                DoneNotificationFunction._doneEvent.WaitOne();
                host.Stop();
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            JobHostConfiguration config = new JobHostConfiguration();
            //config.Tracing.Trace = new ConsoleTraceWriter(TraceLevel.Verbose);
            config.UseRedis();
            
            JobHost host = new JobHost(config);
            host.Start();

            // Give subscriber chance to startup
            Task.Delay(5000).Wait();

            host.Call(typeof(Functions).GetMethod("SendSimplePubSubMessage"));
            host.Call(typeof(Functions).GetMethod("SendPubSubMessage"));
            host.Call(typeof(Functions).GetMethod("SendPubSubMessageIdChannel"));
            host.Call(typeof(Functions).GetMethod("AddSimpleCacheMessage"));
            host.Call(typeof(Functions).GetMethod("AddCacheMessage"));
            host.Call(typeof(Functions).GetMethod("AddCacheMessage"));

            Console.CancelKeyPress += (sender, e) =>
            {
                host.Stop();
            };

            while (true)
            {
                Thread.Sleep(500);
            }
        }
コード例 #4
0
        public static void Main(string[] args)
        {
            JobHostConfiguration config = new JobHostConfiguration();

            config.Tracing.ConsoleLevel = TraceLevel.Verbose;

            // Set to a short polling interval to facilitate local
            // debugging. You wouldn't want to run prod this way.
            config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(2);

            FilesConfiguration filesConfig = new FilesConfiguration();
            if (string.IsNullOrEmpty(filesConfig.RootPath))
            {
                // when running locally, set this to a valid directory
                filesConfig.RootPath = @"c:\temp\files";
            }
            EnsureSampleDirectoriesExist(filesConfig.RootPath);

            config.UseFiles(filesConfig);
            config.UseTimers();
            config.UseSample();
            config.UseCore();
            var sendGridConfiguration = new SendGridConfiguration()
            {
                ToAddress = "*****@*****.**",
                FromAddress = new MailAddress("*****@*****.**", "WebJobs Extensions Samples")
            };
            config.UseSendGrid(sendGridConfiguration);

            ConfigureTraceMonitor(config, sendGridConfiguration);

            WebHooksConfiguration webHooksConfig = new WebHooksConfiguration();
            webHooksConfig.UseReceiver<GitHubWebHookReceiver>();
            config.UseWebHooks(webHooksConfig);

            JobHost host = new JobHost(config);

            host.Call(typeof(MiscellaneousSamples).GetMethod("ExecutionContext"));
            host.Call(typeof(FileSamples).GetMethod("ReadWrite"));
            host.Call(typeof(SampleSamples).GetMethod("Sample_BindToStream"));
            host.Call(typeof(SampleSamples).GetMethod("Sample_BindToString"));
            host.Call(typeof(TableSamples).GetMethod("CustomBinding"));

            // When running in Azure Web Apps, a JobHost will gracefully shut itself
            // down, ensuring that all listeners are stopped, etc. For this sample,
            // we want to ensure that same behavior when the console app window is
            // closed. This ensures that Singleton locks that are taken are released
            // immediately, etc.
            ShutdownHandler.Register(() => { host.Stop(); });

            host.RunAndBlock();
        }
コード例 #5
0
        static void Main()
        {
            CreateDemoData();

            JobHost host = new JobHost();
            host.Start();

            // Stop the host if Ctrl + C/Ctrl + Break is pressed
            Console.CancelKeyPress += (sender, args) =>
            {
                host.Stop();
            };

            while(true)
            {
                Thread.Sleep(500);
            }
        }
        private async Task RunTimerJobTest(Type jobClassType, Func<bool> condition)
        {
            ExplicitTypeLocator locator = new ExplicitTypeLocator(jobClassType);
            JobHostConfiguration config = new JobHostConfiguration
            {
                TypeLocator = locator
            };
            config.UseTimers();
            JobHost host = new JobHost(config);

            host.Start();

            await TestHelpers.Await(() =>
            {
                return condition();
            });

            host.Stop();
        }
        private void InvokeBlobFunctionAndWaitForResult(
            MethodInfo function, 
            string triggerMessage = null, 
            string inputMessage = null)
        {
            if (triggerMessage ==null)
            {
                triggerMessage = "trigger-content-";
            }
            if (inputMessage ==null)
            {
                inputMessage = "input-content";
            }

            string blobPartialName = function.Name.ToLowerInvariant();

            CloudBlobClient blobClient = StorageAccount.CloudStorageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference(BlobArgumentsDisplayFunctions.ContainerName);
            container.CreateIfNotExists();

            container
                .GetBlockBlobReference(blobPartialName + "-trigger")
                .UploadText(triggerMessage);
            container
                .GetBlockBlobReference(blobPartialName + "-in")
                .UploadText(inputMessage);

            JobHostConfiguration hostConfiguration = new JobHostConfiguration(StorageAccount.ConnectionString)
            {
                TypeLocator = new ExplicitTypeLocator(
                    typeof(BlobArgumentsDisplayFunctions),
                    typeof(BlobArgumentsDisplayFunctions.POCOBinder),
                    typeof(DoneNotificationFunction))
            };

            using (JobHost host = new JobHost(hostConfiguration))
            using (DoneNotificationFunction._doneEvent = new ManualResetEvent(initialState: false))
            {
                host.Start();
                DoneNotificationFunction._doneEvent.WaitOne();
                host.Stop();
            }
        }
コード例 #8
0
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage
        static void Main()
        {
            var client = new KeyVault(new Uri(CloudConfigurationManager.GetSetting("KeyVault")));

            var jobStorage = client.Secret.GetSecretByName("JobStorage");
            var sb = client.Secret.GetSecretByName("ServiceBus");

            if (jobStorage.Value != CloudConfigurationManager.GetSetting("JobStorage"))
            {
                jobStorage = new Secret()
                {
                    ContentType = "String",
                    Name = "JobStorage",
                    Value = CloudConfigurationManager.GetSetting("JobStorage")
                };

                jobStorage = client.Secret.CreateSecret("JobStorage", jobStorage);
            }

            if (sb.Value != CloudConfigurationManager.GetSetting("ServiceBus"))
            {
                sb = new Secret()
                {
                    ContentType = "String",
                    Name = "ServiceBus",
                    Value = CloudConfigurationManager.GetSetting("ServiceBus")
                };

                sb = client.Secret.CreateSecret("ServiceBus", sb);
            }

            var jobStorageConnString = jobStorage.Value;

            var host = new JobHost(new JobHostConfiguration(jobStorageConnString));

            host.Start();

            Console.WriteLine("Bootstrapped");

            host.Stop();
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: alpaix/nebula
        static void Main(string[] vargStrings)
        {
            var configuration = new JobHostConfiguration();
            configuration.Queues.MaxPollingInterval = TimeSpan.FromSeconds(30);
            configuration.Queues.MaxDequeueCount = 10;
            configuration.Queues.BatchSize = 1;

            var host = new JobHost(configuration);
            host.Start();

            // Stop the host if Ctrl + C/Ctrl + Break is pressed
            Console.CancelKeyPress += (sender, args) =>
            {
                host.Stop();
            };

            while (true)
            {
                Thread.Sleep(500);
            }
        }
        private void RunEndToEnd()
        {
            // create the initial messgage that starts the function chain
            CreateStartMessage();

            using (JobHost host = new JobHost(_hostConfiguration))
            using (DoneNotificationFunction._doneEvent = new ManualResetEvent(initialState: false))
            {
                host.Start();
                DoneNotificationFunction._doneEvent.WaitOne();
                host.Stop();
            }
        }