Esempio n. 1
0
 static void JobHost()
 {
     var config = new JobHostConfiguration();
     var host = new JobHost(config);
     host.RunAndBlock();
     host.Start();
 }
        public void Apply(JobHostConfiguration config)
        {
            ApplyConfiguration(config);

            Type type = FunctionGenerator.Generate(Functions);
            config.TypeLocator = new TypeLocator(type);
        }
        public static void Run(string connectionString)
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);

            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();
            CreateTestQueues(queueClient);

            try
            {
                CloudQueue firstQueue = queueClient.GetQueueReference(_nameResolver.ResolveInString(FunctionChainingPerfTest.FirstQueueName));
                firstQueue.AddMessage(new CloudQueueMessage("Test"));

                _startBlock = MeasurementBlock.BeginNew(0, HostStartMetric);

                JobHostConfiguration hostConfig = new JobHostConfiguration(connectionString);
                hostConfig.NameResolver = _nameResolver;
                hostConfig.TypeLocator = new FakeTypeLocator(typeof(FunctionChainingPerfTest));

                JobHost host = new JobHost(hostConfig);
                _tokenSource = new CancellationTokenSource();
                Task stopTask = null;
                _tokenSource.Token.Register(() => stopTask = host.StopAsync());
                host.RunAndBlock();
                stopTask.GetAwaiter().GetResult();
            }
            finally
            {
                DeleteTestQueues(queueClient);
            }
        }
Esempio n. 4
0
        public int Main(string[] args)
        {
            var builder = new ConfigurationBuilder();
            //builder.Add(new JsonConfigurationSource("config.json"));
            builder.AddJsonFile("config.json");
            var config = builder.Build();
            var webjobsConnectionString = config["Data:AzureWebJobsStorage:ConnectionString"];
            var dbConnectionString = config["Data:DefaultConnection:ConnectionString"];

            if (string.IsNullOrWhiteSpace(webjobsConnectionString))
            {
                Console.WriteLine("The configuration value for Azure Web Jobs Connection String is missing.");
                return 10;
            }

            if (string.IsNullOrWhiteSpace(dbConnectionString))
            {
                Console.WriteLine("The configuration value for Database Connection String is missing.");
                return 10;
            }

            var jobHostConfig = new JobHostConfiguration(webjobsConnectionString);
            var host = new JobHost(jobHostConfig);

            host.RunAndBlock();
            return 0;
        }
        static void Main()
        {
            JobHost host;
            string connectionString;
            // To run webjobs locally, can't use storage emulator
            // for local execution, use connection string stored in environment vatiable
            if ((connectionString = Environment.GetEnvironmentVariable("AzureStorageQueueTransport.ConnectionString")) != null)
            {
                var configuration = new JobHostConfiguration
                {
                    DashboardConnectionString = connectionString,
                    StorageConnectionString = connectionString
                };
                host = new JobHost(configuration);
            }
            // for production, use DashboardConnectionString and StorageConnectionString defined at Azure website
            else
            {
                host = new JobHost();
            }

            Console.WriteLine("Starting VideoStore.Operations host");
            host.Call(typeof(Functions).GetMethod("Host"));
            host.RunAndBlock();
        }
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage
        static void Main()
        {
            var config = new JobHostConfiguration();
            var slackConfig = new SlackConfiguration();
            WebHooksConfiguration webhookConfig;

            if(config.IsDevelopment)
            {
                config.UseDevelopmentSettings();
                webhookConfig = new WebHooksConfiguration(3000);
            }
            else
            {
                webhookConfig = new WebHooksConfiguration();
            }

            // These are optional and will be applied if no other value is specified.
            /*
            slackConfig.WebHookUrl = "";
            // IT IS A BAD THING TO HARDCODE YOUR WEBHOOKURL, USE THE APP SETTING "AzureWebJobsSlackWebHookKeyName"
            slackConfig.IconEmoji = "";
            slackConfig.Username = "";
            slackConfig.Channel = "";
            */

            config.UseSlack(slackConfig);
            config.UseWebHooks(webhookConfig);

            var host = new JobHost(config);
            // The following code ensures that the WebJob will be running continuously
            host.RunAndBlock();
        }
 // Please set the following connection strings in app.config for this WebJob to run:
 // AzureWebJobsDashboard and AzureWebJobsStorage
 static void Main()
 {
     var config = new JobHostConfiguration();
     config.UseTimers();
     var host = new JobHost(config);
     host.RunAndBlock();
 }
Esempio n. 8
0
 // Please set the following connection strings in app.config for this WebJob to run:
 // AzureWebJobsDashboard and AzureWebJobsStorage
 static void Main()
 {
     JobHostConfiguration config = new JobHostConfiguration();
       config.UseServiceBus();
       JobHost host = new JobHost(config);
       host.RunAndBlock();
 }
Esempio n. 9
0
    static void Main()
        {
            // setup unobserved exceptions
            TaskScheduler.UnobservedTaskException += Program.handleUnObservedExceptions;



         // Setup configuration sources.
        Configuration = new Configuration()
                .AddEnvironmentVariables("APPSETTING_");

            var storageCstr = GetConnectionString();

            JobHostConfiguration config = new JobHostConfiguration(storageCstr);
            config.Queues.BatchSize = 1; //Number of messages parallel processed in parallel. Will need some concurrency check before increasing.
            config.Queues.MaxDequeueCount = 4;
            config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(15);
            JobHost host = new JobHost(config);
            Console.WriteLine("Web Job starting..");

            // TEST Lines
            //ProvisioningLibrary.WebJobController w = new WebJobController(Configuration);
            //w.SubmitActionInQueue("8fd8fbfc-8fb6-4e95-ae17-aa4779423cb8", ResourceAction.Start );

            // The following code ensures that the WebJob will be running continuously
            host.RunAndBlock();
        }
        public void ApplyConfiguration_Queues()
        {
            JObject config = new JObject();
            config["id"] = ID;
            JObject queuesConfig = new JObject();
            config["queues"] = queuesConfig;
            JobHostConfiguration jobHostConfig = new JobHostConfiguration();

            ScriptHost.ApplyConfiguration(config, jobHostConfig);

            Assert.Equal(ID, jobHostConfig.HostId);
            Assert.Equal(60 * 1000, jobHostConfig.Queues.MaxPollingInterval.TotalMilliseconds);
            Assert.Equal(16, jobHostConfig.Queues.BatchSize);
            Assert.Equal(5, jobHostConfig.Queues.MaxDequeueCount);
            Assert.Equal(8, jobHostConfig.Queues.NewBatchThreshold);

            queuesConfig["maxPollingInterval"] = 5000;
            queuesConfig["batchSize"] = 17;
            queuesConfig["maxDequeueCount"] = 3;
            queuesConfig["newBatchThreshold"] = 123;

            ScriptHost.ApplyConfiguration(config, jobHostConfig);

            Assert.Equal(5000, jobHostConfig.Queues.MaxPollingInterval.TotalMilliseconds);
            Assert.Equal(17, jobHostConfig.Queues.BatchSize);
            Assert.Equal(3, jobHostConfig.Queues.MaxDequeueCount);
            Assert.Equal(123, jobHostConfig.Queues.NewBatchThreshold);
        }
        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();
            }
        }
Esempio n. 12
0
        public static void Main(string[] args)
        {
            // Set up default WebHook logger
            ILogger logger = new TraceLogger();

            // Set the WebHook Store we want to get WebHook subscriptions from. Azure store requires
            // a valid Azure Storage connection string named MS_AzureStoreConnectionString.
            IWebHookStore store = AzureWebHookStore.CreateStore(logger);

            // Set the sender we want to actually send out the WebHooks. We could also 
            // enqueue messages for scale out.
            IWebHookSender sender = new DataflowWebHookSender(logger);

            // Set up WebHook manager which we use for creating notifications.
            Manager = new WebHookManager(store, sender, logger);

            // Initialize WebJob
            var listener = ConfigurationManager.ConnectionStrings["WebHookListener"].ConnectionString;
            JobHostConfiguration config = new JobHostConfiguration
            {
                StorageConnectionString = listener
            };
            JobHost host = new JobHost(config);
            host.RunAndBlock();
        }
        public void ApplyConfiguration_Singleton()
        {
            JObject config = new JObject();
            config["id"] = ID;
            JObject singleton = new JObject();
            config["singleton"] = singleton;
            JobHostConfiguration jobHostConfig = new JobHostConfiguration();

            ScriptHost.ApplyConfiguration(config, jobHostConfig);

            Assert.Equal(ID, jobHostConfig.HostId);
            Assert.Equal(15, jobHostConfig.Singleton.LockPeriod.TotalSeconds);
            Assert.Equal(1, jobHostConfig.Singleton.ListenerLockPeriod.TotalMinutes);
            Assert.Equal(1, jobHostConfig.Singleton.ListenerLockRecoveryPollingInterval.TotalMinutes);
            Assert.Equal(1, jobHostConfig.Singleton.LockAcquisitionTimeout.TotalMinutes);
            Assert.Equal(3, jobHostConfig.Singleton.LockAcquisitionPollingInterval.TotalSeconds);

            singleton["lockPeriod"] = "00:00:17";
            singleton["listenerLockPeriod"] = "00:00:22";
            singleton["listenerLockRecoveryPollingInterval"] = "00:00:33";
            singleton["lockAcquisitionTimeout"] = "00:05:00";
            singleton["lockAcquisitionPollingInterval"] = "00:00:08";

            ScriptHost.ApplyConfiguration(config, jobHostConfig);

            Assert.Equal(17, jobHostConfig.Singleton.LockPeriod.TotalSeconds);
            Assert.Equal(22, jobHostConfig.Singleton.ListenerLockPeriod.TotalSeconds);
            Assert.Equal(33, jobHostConfig.Singleton.ListenerLockRecoveryPollingInterval.TotalSeconds);
            Assert.Equal(5, jobHostConfig.Singleton.LockAcquisitionTimeout.TotalMinutes);
            Assert.Equal(8, jobHostConfig.Singleton.LockAcquisitionPollingInterval.TotalSeconds);
        }
        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);
            }
        }
        public void Initialize_PerformsExpectedRegistrations()
        {
            JobHostConfiguration config = new JobHostConfiguration();
            config.AddService<INameResolver>(new RandomNameResolver());

            ServiceBusConfiguration serviceBusConfig = new ServiceBusConfiguration();
            ServiceBusExtensionConfig serviceBusExtensionConfig = new ServiceBusExtensionConfig(serviceBusConfig);

            IExtensionRegistry extensions = config.GetService<IExtensionRegistry>();
            ITriggerBindingProvider[] triggerBindingProviders = extensions.GetExtensions<ITriggerBindingProvider>().ToArray();
            Assert.Equal(0, triggerBindingProviders.Length);
            IBindingProvider[] bindingProviders = extensions.GetExtensions<IBindingProvider>().ToArray();
            Assert.Equal(0, bindingProviders.Length);

            ExtensionConfigContext context = new ExtensionConfigContext
            {
                Config = config,
                Trace = new TestTraceWriter(TraceLevel.Verbose)
            };
            serviceBusExtensionConfig.Initialize(context);

            // ensure the ServiceBusTriggerAttributeBindingProvider was registered
            triggerBindingProviders = extensions.GetExtensions<ITriggerBindingProvider>().ToArray();
            Assert.Equal(1, triggerBindingProviders.Length);
            ServiceBusTriggerAttributeBindingProvider triggerBindingProvider = (ServiceBusTriggerAttributeBindingProvider)triggerBindingProviders[0];
            Assert.NotNull(triggerBindingProvider);

            // ensure the ServiceBusAttributeBindingProvider was registered
            bindingProviders = extensions.GetExtensions<IBindingProvider>().ToArray();
            Assert.Equal(1, bindingProviders.Length);
            ServiceBusAttributeBindingProvider bindingProvider = (ServiceBusAttributeBindingProvider)bindingProviders[0];
            Assert.NotNull(bindingProvider);
        }
Esempio n. 16
0
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage
        public static void Main()
        {
            try
            {
#if !DEBUG
                LogManager.Logger = new OneTimeLogger(new ProfileRepository());
#endif

                LogManager.Log("Start !");
                JobHostConfiguration config = new JobHostConfiguration();
                config.Queues.BatchSize = 1;
                var host = new JobHost(config);

                Init();
                Run();
#if DEBUG
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
#else
                LogManager.Log("This is release !");
                // The following code ensures that the WebJob will be running continuously
                //host.RunAndBlock();
#endif
            }
            catch (Exception ex)
            {
                LogManager.Log(ex);
            }
            finally
            {
                LogManager.Log("End");
                LogManager.FlushLogger();
            }
        }
Esempio n. 17
0
        public int Main(string[] args)
        {
            var builder = new ConfigurationBuilder();
            builder.Add(new JsonConfigurationProvider("config.json"));
            var config = builder.Build();
            var webjobsConnectionString = config["Data:AzureWebJobsStorage:ConnectionString"];
            var dbConnectionString = config["Data:DefaultConnection:ConnectionString"];
            if (string.IsNullOrWhiteSpace(webjobsConnectionString))
            {
                Console.WriteLine("The configuration value for Azure Web Jobs Connection String is missing.");
                return 10;
            }

            if (string.IsNullOrWhiteSpace(dbConnectionString))
            {
                Console.WriteLine("The configuration value for Database Connection String is missing.");
                return 10;
            }

            var jobHostConfig = new JobHostConfiguration(config["Data:AzureWebJobsStorage:ConnectionString"]);
            var host = new JobHost(jobHostConfig);
            var methodInfo = typeof(Functions).GetMethods().First();

            host.Call(methodInfo);
            return 0;
        }
        public ServiceBusArgumentsDisplayTestsFixture()
            : base(cleanStorageAccount: true)
        {
            _hostConfiguration = new JobHostConfiguration(StorageAccount.ConnectionString)
            {
                TypeLocator = new ExplicitTypeLocator(
                    typeof(ServiceBusArgumentsDisplayFunctions),
                    typeof(DoneNotificationFunction))
            };

            #if VNEXT_SDK
            ServiceBusConfiguration serviceBusConfig = new ServiceBusConfiguration();
            serviceBusConfig.ConnectionString = ServiceBusAccount;
            _serviceBusConnectionString = serviceBusConfig.ConnectionString;
            _hostConfiguration.UseServiceBus(serviceBusConfig);
            #else
            _serviceBusConnectionString = ServiceBusAccount;
            _hostConfiguration.ServiceBusConnectionString = _serviceBusConnectionString;
            #endif

            _namespaceManager = NamespaceManager.CreateFromConnectionString(_serviceBusConnectionString);

            // ensure we're starting in a clean state
            CleanServiceBusQueues();

            // now run the entire end to end scenario, causing all the job functions
            // to be invoked
            RunEndToEnd();
        }
        public void UseServiceBus_NoServiceBusConfiguration_PerformsExpectedRegistration()
        {
            JobHostConfiguration config = new JobHostConfiguration();
            string serviceBusConnection = "test service bus connection";
#pragma warning disable 0618
            config.ServiceBusConnectionString = serviceBusConnection;
#pragma warning restore 0618

            IExtensionRegistry extensions = config.GetService<IExtensionRegistry>();
            IExtensionConfigProvider[] configProviders = extensions.GetExtensions<IExtensionConfigProvider>().ToArray();
            Assert.Equal(0, configProviders.Length);

            config.UseServiceBus();

            // verify that the service bus config provider was registered
            configProviders = extensions.GetExtensions<IExtensionConfigProvider>().ToArray();
            Assert.Equal(1, configProviders.Length);

            ServiceBusExtensionConfig serviceBusExtensionConfig = (ServiceBusExtensionConfig)configProviders.Single();

            // verify that a default ServiceBusConfiguration was created, with the host (obsolete)
            // service bus connection string propagated
#pragma warning disable 0618
            Assert.Equal(serviceBusConnection, serviceBusExtensionConfig.Config.ConnectionString);
#pragma warning restore 0618
        }
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage
        static void Main()
        {
            Console.WriteLine("*************************************************************************");
            Console.WriteLine("WebJobUsageHistory:Main starting. DateTimeUTC: {0}", DateTime.UtcNow);

            /*/
            DateTime sdt = DateTime.Now.AddYears(-3);
            DateTime edt = DateTime.Now.AddDays(-1);
            BillingRequest br = new BillingRequest("30d4242f-1afc-49d9-a993-59d0de83b5bd",
                                                    "72f988bf-86f1-41af-91ab-2d7cd011db47",
                                                    sdt, //Convert.ToDateTime("2015-10-28 00:00:00.000"),
                                                    edt);//Convert.ToDateTime("2015-10-29 00:00:00.000"));
            Functions.ProcessQueueMessage(br);
            return;
            /**/

            JobHostConfiguration config = new JobHostConfiguration();
            config.Queues.BatchSize = 3;
            config.Queues.MaxDequeueCount = 3;
            config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(15);

            var host = new JobHost(config);
            // The following code ensures that the WebJob will be running continuously
            host.RunAndBlock();
        }
		static void Main()
		{
			_servicesBusConnectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(ConnectionStringNames.ServiceBus);
			namespaceManager = NamespaceManager.CreateFromConnectionString(_servicesBusConnectionString);

			if (!namespaceManager.QueueExists(nameof(Step1)))
			{
				namespaceManager.CreateQueue(nameof(Step1));
			}
			if (!namespaceManager.QueueExists(nameof(Step2)))
			{
				namespaceManager.CreateQueue(nameof(Step2));
			}

			JobHostConfiguration config = new JobHostConfiguration();
			config.UseServiceBus();



			var host = new JobHost(config);

			CreateStartMessage();

			host.RunAndBlock();
		}
 public ScriptHostConfiguration()
 {
     HostConfig = new JobHostConfiguration();
     FileWatchingEnabled = true;
     RootScriptPath = Environment.CurrentDirectory;
     RootLogPath = Path.Combine(Path.GetTempPath(), "Functions");            
 }
        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);
            }
        }
        public StorageScheduleMonitorTests()
        {
            _hostConfig = new JobHostConfiguration();
            _hostConfig.HostId = TestHostId;
            _scheduleMonitor = new StorageScheduleMonitor(_hostConfig);

            Cleanup();
        }
 public WebHookDispatcher(WebHooksConfiguration webHooksConfig, JobHost host, JobHostConfiguration config, TraceWriter trace)
 {
     _functions = new ConcurrentDictionary<string, ITriggeredFunctionExecutor>();
     _trace = trace;
     _port = webHooksConfig.Port;
     _types = config.TypeLocator.GetTypes().ToArray();
     _host = host;
 }
Esempio n. 26
0
 // Please set the following connection strings in app.config for this WebJob to run:
 // AzureWebJobsDashboard and AzureWebJobsStorage
 static void Main()
 {
     JobHostConfiguration config = new JobHostConfiguration();
     config.Queues.MaxPollingInterval = TimeSpan.FromSeconds(15);
     var host = new JobHost(config);
     // The following code ensures that the WebJob will be running continuously
     host.RunAndBlock();
 }
        public static NodeScriptHost Create(ScriptHostConfiguration scriptConfig)
        {
            JobHostConfiguration config = new JobHostConfiguration();
            NodeScriptHost scriptHost = new NodeScriptHost(config, scriptConfig);
            scriptHost.Initialize();

            return scriptHost;
        }
Esempio n. 28
0
        static void Main()
        {
            JobHostConfiguration config = new JobHostConfiguration();

            var host = new JobHost(config);
            
            host.Call(typeof(Functions).GetMethod("QueueBackup"));
        }
 public void UseServiceBus_ThrowsArgumentNull_WhenServiceBusConfigIsNull()
 {
     JobHostConfiguration config = new JobHostConfiguration();
     ArgumentNullException exception = Assert.Throws<ArgumentNullException>(() =>
         {
             config.UseServiceBus(null);
         });
     Assert.Equal("serviceBusConfig", exception.ParamName);
 }
Esempio n. 30
0
 public EndToEndTraceHelper(JobHostConfiguration config, ILogger logger)
 {
     this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
 }
 public CoreExtensionsScriptBindingProvider(JobHostConfiguration config, JObject hostMetadata, TraceWriter traceWriter)
     : base(config, hostMetadata, traceWriter)
 {
 }
Esempio n. 32
0
        public async Task TableFilterTest()
        {
            // Reinitialize the name resolver to avoid conflicts
            _resolver = new RandomNameResolver();

            JobHostConfiguration hostConfig = new JobHostConfiguration()
            {
                NameResolver = _resolver,
                TypeLocator  = new FakeTypeLocator(
                    this.GetType(),
                    typeof(BlobToCustomObjectBinder))
            };

            // write test entities
            string           testTableName = _resolver.ResolveInString(TableName);
            CloudTableClient tableClient   = _storageAccount.CreateCloudTableClient();
            CloudTable       table         = tableClient.GetTableReference(testTableName);
            await table.CreateIfNotExistsAsync();

            var operation = new TableBatchOperation();

            operation.Insert(new Person
            {
                PartitionKey = "1",
                RowKey       = "1",
                Name         = "Lary",
                Age          = 20,
                Location     = "Seattle"
            });
            operation.Insert(new Person
            {
                PartitionKey = "1",
                RowKey       = "2",
                Name         = "Moe",
                Age          = 35,
                Location     = "Seattle"
            });
            operation.Insert(new Person
            {
                PartitionKey = "1",
                RowKey       = "3",
                Name         = "Curly",
                Age          = 45,
                Location     = "Texas"
            });
            operation.Insert(new Person
            {
                PartitionKey = "1",
                RowKey       = "4",
                Name         = "Bill",
                Age          = 28,
                Location     = "Tam O'Shanter"
            });
            await table.ExecuteBatchAsync(operation);

            JobHost host       = new JobHost(hostConfig);
            var     methodInfo = this.GetType().GetMethod("TableWithFilter", BindingFlags.Public | BindingFlags.Static);
            var     input      = new Person {
                Age = 25, Location = "Seattle"
            };
            string json      = JsonConvert.SerializeObject(input);
            var    arguments = new { person = json };
            await host.CallAsync(methodInfo, arguments);

            // wait for test results to appear
            await TestHelpers.Await(() => TestResult != null);

            JArray results = (JArray)TestResult;

            Assert.Equal(1, results.Count);

            input = new Person {
                Age = 25, Location = "Tam O'Shanter"
            };
            json      = JsonConvert.SerializeObject(input);
            arguments = new { person = json };
            await host.CallAsync(methodInfo, arguments);

            await TestHelpers.Await(() => TestResult != null);

            results = (JArray)TestResult;
            Assert.Equal(1, results.Count);
            Assert.Equal("Bill", (string)results[0]["Name"]);
        }
Esempio n. 33
0
            public TestFixture()
            {
                RandomNameResolver   nameResolver      = new RandomNameResolver();
                JobHostConfiguration hostConfiguration = new JobHostConfiguration()
                {
                    NameResolver = nameResolver,
                    TypeLocator  = new FakeTypeLocator(typeof(MultipleStorageAccountsEndToEndTests)),
                };

                Config = hostConfiguration;

                Account1 = CloudStorageAccount.Parse(hostConfiguration.StorageConnectionString);
                string secondaryConnectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(Secondary);

                Account2 = CloudStorageAccount.Parse(secondaryConnectionString);

                CleanContainers();

                CloudBlobClient    blobClient1     = Account1.CreateCloudBlobClient();
                string             inputName       = nameResolver.ResolveInString(Input);
                CloudBlobContainer inputContainer1 = blobClient1.GetContainerReference(inputName);

                inputContainer1.Create();
                string outputName = nameResolver.ResolveWholeString(Output);

                OutputContainer1 = blobClient1.GetContainerReference(outputName);
                OutputContainer1.CreateIfNotExists();

                CloudBlobClient    blobClient2     = Account2.CreateCloudBlobClient();
                CloudBlobContainer inputContainer2 = blobClient2.GetContainerReference(inputName);

                inputContainer2.Create();
                OutputContainer2 = blobClient2.GetContainerReference(outputName);
                OutputContainer2.CreateIfNotExists();

                CloudQueueClient queueClient1 = Account1.CreateCloudQueueClient();
                CloudQueue       inputQueue1  = queueClient1.GetQueueReference(inputName);

                inputQueue1.CreateIfNotExists();
                OutputQueue1 = queueClient1.GetQueueReference(outputName);
                OutputQueue1.CreateIfNotExists();

                CloudQueueClient queueClient2 = Account2.CreateCloudQueueClient();
                CloudQueue       inputQueue2  = queueClient2.GetQueueReference(inputName);

                inputQueue2.CreateIfNotExists();
                OutputQueue2 = queueClient2.GetQueueReference(outputName);
                OutputQueue2.CreateIfNotExists();

                CloudTableClient tableClient1    = Account1.CreateCloudTableClient();
                string           outputTableName = nameResolver.ResolveWholeString(OutputTableName);

                OutputTable1 = tableClient1.GetTableReference(outputTableName);
                OutputTable2 = Account2.CreateCloudTableClient().GetTableReference(outputTableName);

                // upload some test blobs to the input containers of both storage accounts
                CloudBlockBlob blob = inputContainer1.GetBlockBlobReference("blob1");

                blob.UploadText(TestData);
                blob = inputContainer2.GetBlockBlobReference("blob2");
                blob.UploadText(TestData);

                // upload some test queue messages to the input queues of both storage accounts
                inputQueue1.AddMessage(new CloudQueueMessage(TestData));
                inputQueue2.AddMessage(new CloudQueueMessage(TestData));

                Host = new JobHost(hostConfiguration);
                Host.Start();
            }
Esempio n. 34
0
            public TestFixture()
            {
                JobHostConfiguration config = new JobHostConfiguration();

                StorageAccount = CloudStorageAccount.Parse(config.StorageConnectionString);
            }
Esempio n. 35
0
        public async Task BadQueueMessageE2ETests()
        {
            // This test ensures that the host does not crash on a bad message (it previously did)
            // Insert a bad message into a queue that should:
            // - trigger BadMessage_CloudQueueMessage, which will put it into a second queue that will
            // - trigger BadMessage_String, which should fail
            // - BadMessage_String should fail repeatedly until it is moved to the poison queue
            // The test will watch that poison queue to know when to complete

            // Reinitialize the name resolver to avoid conflicts
            _resolver = new RandomNameResolver();

            JobHostConfiguration hostConfig = new JobHostConfiguration()
            {
                NameResolver = _resolver,
                TypeLocator  = new FakeTypeLocator(
                    this.GetType(),
                    typeof(BlobToCustomObjectBinder))
            };
            var tracer = new TestTraceWriter(TraceLevel.Verbose);

            hostConfig.Tracing.Tracers.Add(tracer);

            // The jobs host is started
            JobHost host = new JobHost(hostConfig);

            host.Start();

            // use reflection to construct a bad message:
            // - use a GUID as the content, which is not a valid base64 string
            // - pass 'true', to indicate that it is a base64 string
            string messageContent = Guid.NewGuid().ToString();

            object[]          parameters = new object[] { messageContent, true };
            CloudQueueMessage message    = Activator.CreateInstance(typeof(CloudQueueMessage),
                                                                    BindingFlags.Instance | BindingFlags.NonPublic, null, parameters, null) as CloudQueueMessage;

            var queueClient = _storageAccount.CreateCloudQueueClient();
            var queue       = queueClient.GetQueueReference(_resolver.ResolveInString(BadMessageQueue1));
            await queue.CreateIfNotExistsAsync();

            await queue.ClearAsync();

            // the poison queue will end up off of the second queue
            var poisonQueue = queueClient.GetQueueReference(_resolver.ResolveInString(BadMessageQueue2) + "-poison");
            await poisonQueue.DeleteIfExistsAsync();

            await queue.AddMessageAsync(message);

            CloudQueueMessage poisonMessage = null;
            await TestHelpers.Await(() =>
            {
                bool done = false;
                if (poisonQueue.Exists())
                {
                    poisonMessage = poisonQueue.GetMessage();
                    done          = poisonMessage != null;
                }
                return(done);
            });

            host.Stop();

            // find the raw string to compare it to the original
            Assert.NotNull(poisonMessage);
            var    propInfo  = typeof(CloudQueueMessage).GetProperty("RawString", BindingFlags.Instance | BindingFlags.NonPublic);
            string rawString = propInfo.GetValue(poisonMessage) as string;

            Assert.Equal(messageContent, rawString);

            // Make sure the functions were called correctly
            Assert.Equal(1, _badMessage1Calls);
            Assert.Equal(0, _badMessage2Calls);

            // make sure the exception is being properly logged
            var errors = tracer.Traces.Where(t => t.Level == TraceLevel.Error);

            Assert.True(errors.All(t => t.Exception.InnerException.InnerException is FormatException));
        }
        public async Task Generate_EndToEnd()
        {
            // construct our TimerTrigger attribute ([TimerTrigger("00:00:02", RunOnStartup = true)])
            Collection <ParameterDescriptor> parameters = new Collection <ParameterDescriptor>();
            ParameterDescriptor    parameter            = new ParameterDescriptor("timerInfo", typeof(TimerInfo));
            ConstructorInfo        ctorInfo             = typeof(TimerTriggerAttribute).GetConstructor(new Type[] { typeof(string) });
            PropertyInfo           runOnStartupProperty = typeof(TimerTriggerAttribute).GetProperty("RunOnStartup");
            CustomAttributeBuilder attributeBuilder     = new CustomAttributeBuilder(
                ctorInfo,
                new object[] { "00:00:02" },
                new PropertyInfo[] { runOnStartupProperty },
                new object[] { true });

            parameter.CustomAttributes.Add(attributeBuilder);
            parameters.Add(parameter);

            // create the FunctionDefinition
            FunctionMetadata   metadata = new FunctionMetadata();
            TestInvoker        invoker  = new TestInvoker();
            FunctionDescriptor function = new FunctionDescriptor("TimerFunction", invoker, metadata, parameters, null, null, null);
            Collection <FunctionDescriptor> functions = new Collection <FunctionDescriptor>();

            functions.Add(function);

            // Get the Type Attributes (in this case, a TimeoutAttribute)
            ScriptHostConfiguration scriptConfig = new ScriptHostConfiguration();

            scriptConfig.FunctionTimeout = TimeSpan.FromMinutes(5);
            Collection <CustomAttributeBuilder> typeAttributes = ScriptHost.CreateTypeAttributes(scriptConfig);

            // generate the Type
            Type functionType = FunctionGenerator.Generate("TestScriptHost", "TestFunctions", typeAttributes, functions);

            // verify the generated function
            MethodInfo       method           = functionType.GetMethod("TimerFunction");
            TimeoutAttribute timeoutAttribute = (TimeoutAttribute)functionType.GetCustomAttributes().Single();

            Assert.Equal(TimeSpan.FromMinutes(5), timeoutAttribute.Timeout);
            Assert.True(timeoutAttribute.ThrowOnTimeout);
            Assert.True(timeoutAttribute.TimeoutWhileDebugging);
            ParameterInfo         triggerParameter = method.GetParameters()[0];
            TimerTriggerAttribute triggerAttribute = triggerParameter.GetCustomAttribute <TimerTriggerAttribute>();

            Assert.NotNull(triggerAttribute);

            // start the JobHost which will start running the timer function
            JobHostConfiguration config = new JobHostConfiguration()
            {
                TypeLocator = new TypeLocator(functionType)
            };

            config.UseTimers();
            JobHost host = new JobHost(config);

            await host.StartAsync();

            await Task.Delay(3000);

            await host.StopAsync();

            // verify our custom invoker was called
            Assert.True(invoker.InvokeCount >= 2);
        }
Esempio n. 37
0
        private async Task ServiceBusEndToEndInternal(Type jobContainerType, JobHost host = null, bool verifyLogs = true)
        {
            StringWriter consoleOutput = null;
            TextWriter   hold          = null;

            if (verifyLogs)
            {
                consoleOutput = new StringWriter();
                hold          = Console.Out;
                Console.SetOut(consoleOutput);
            }

            if (host == null)
            {
                JobHostConfiguration config = new JobHostConfiguration()
                {
                    NameResolver = _nameResolver,
                    TypeLocator  = new FakeTypeLocator(jobContainerType)
                };
                config.UseServiceBus(_serviceBusConfig);
                host = new JobHost(config);
            }

            string startQueueName  = ResolveName(StartQueueName);
            string secondQueueName = startQueueName.Replace("start", "1");
            string queuePrefix     = startQueueName.Replace("-queue-start", "");
            string firstTopicName  = string.Format("{0}-topic/Subscriptions/{0}-queue-topic-1", queuePrefix);
            string secondTopicName = string.Format("{0}-topic/Subscriptions/{0}-queue-topic-2", queuePrefix);

            CreateStartMessage(_serviceBusConfig.ConnectionString, startQueueName);

            _topicSubscriptionCalled1 = new ManualResetEvent(initialState: false);
            _topicSubscriptionCalled2 = new ManualResetEvent(initialState: false);

            await host.StartAsync();

            _topicSubscriptionCalled1.WaitOne(SBTimeout);
            _topicSubscriptionCalled2.WaitOne(SBTimeout);

            // ensure all logs have had a chance to flush
            await Task.Delay(3000);

            // Wait for the host to terminate
            await host.StopAsync();

            host.Dispose();

            Assert.Equal("E2E-SBQueue2SBQueue-SBQueue2SBTopic-topic-1", _resultMessage1);
            Assert.Equal("E2E-SBQueue2SBQueue-SBQueue2SBTopic-topic-2", _resultMessage2);

            if (verifyLogs)
            {
                Console.SetOut(hold);

                string[] consoleOutputLines  = consoleOutput.ToString().Trim().Split(new string[] { Environment.NewLine }, StringSplitOptions.None).OrderBy(p => p).ToArray();
                string[] expectedOutputLines = new string[]
                {
                    "Found the following functions:",
                    string.Format("{0}.SBQueue2SBQueue", jobContainerType.FullName),
                    string.Format("{0}.MultipleAccounts", jobContainerType.FullName),
                    string.Format("{0}.SBQueue2SBTopic", jobContainerType.FullName),
                    string.Format("{0}.SBTopicListener1", jobContainerType.FullName),
                    string.Format("{0}.SBTopicListener2", jobContainerType.FullName),
                    "Job host started",
                    string.Format("Executing '{0}.SBQueue2SBQueue' (Reason='New ServiceBus message detected on '{1}'.', Id=", jobContainerType.Name, startQueueName),
                    string.Format("Executed '{0}.SBQueue2SBQueue' (Succeeded, Id=", jobContainerType.Name),
                    string.Format("Executing '{0}.SBQueue2SBTopic' (Reason='New ServiceBus message detected on '{1}'.', Id=", jobContainerType.Name, secondQueueName),
                    string.Format("Executed '{0}.SBQueue2SBTopic' (Succeeded, Id=", jobContainerType.Name),
                    string.Format("Executing '{0}.SBTopicListener1' (Reason='New ServiceBus message detected on '{1}'.', Id=", jobContainerType.Name, firstTopicName),
                    string.Format("Executed '{0}.SBTopicListener1' (Succeeded, Id=", jobContainerType.Name),
                    string.Format("Executing '{0}.SBTopicListener2' (Reason='New ServiceBus message detected on '{1}'.', Id=", jobContainerType.Name, secondTopicName),
                    string.Format("Executed '{0}.SBTopicListener2' (Succeeded, Id=", jobContainerType.Name),
                    "Job host stopped"
                }.OrderBy(p => p).ToArray();

                bool hasError = consoleOutputLines.Any(p => p.Contains("Function had errors"));
                if (!hasError)
                {
                    for (int i = 0; i < expectedOutputLines.Length; i++)
                    {
                        Assert.StartsWith(expectedOutputLines[i], consoleOutputLines[i]);
                    }
                }
            }
        }
Esempio n. 38
0
 public JobHostContextFactory(IStorageAccountProvider storageAccountProvider, IConsoleProvider consoleProvider, JobHostConfiguration config)
 {
     _storageAccountProvider = storageAccountProvider;
     _consoleProvider        = consoleProvider;
     _config = config;
 }
Esempio n. 39
0
            private async Task Initialize()
            {
                RandomNameResolver   nameResolver      = new RandomNameResolver();
                JobHostConfiguration hostConfiguration = new JobHostConfiguration()
                {
                    NameResolver = nameResolver,
                    TypeLocator  = new FakeTypeLocator(typeof(BlobBindingEndToEndTests)),
                };

                hostConfiguration.AddService <IWebJobsExceptionHandler>(new TestExceptionHandler());

                Config = hostConfiguration;

                StorageAccount = CloudStorageAccount.Parse(hostConfiguration.StorageConnectionString);
                CloudBlobClient blobClient = StorageAccount.CreateCloudBlobClient();

                BlobContainer = blobClient.GetContainerReference(nameResolver.ResolveInString(ContainerName));
                Assert.False(await BlobContainer.ExistsAsync());
                await BlobContainer.CreateAsync();

                OutputBlobContainer = blobClient.GetContainerReference(nameResolver.ResolveInString(OutputContainerName));

                CloudBlobContainer pageBlobContainer = blobClient.GetContainerReference(nameResolver.ResolveInString(PageBlobContainerName));

                Assert.False(await pageBlobContainer.ExistsAsync());
                await pageBlobContainer.CreateAsync();

                CloudBlobContainer hierarchicalBlobContainer = blobClient.GetContainerReference(nameResolver.ResolveInString(HierarchicalBlobContainerName));

                Assert.False(await hierarchicalBlobContainer.ExistsAsync());
                await hierarchicalBlobContainer.CreateAsync();

                CloudBlobContainer appendBlobContainer = blobClient.GetContainerReference(nameResolver.ResolveInString(AppendBlobContainerName));

                Assert.False(await appendBlobContainer.ExistsAsync());
                await appendBlobContainer.CreateAsync();

                Host = new JobHost(hostConfiguration);
                Host.Start();

                // upload some test blobs
                CloudBlockBlob blob = BlobContainer.GetBlockBlobReference("blob1");
                await blob.UploadTextAsync(TestData);

                blob = BlobContainer.GetBlockBlobReference("blob2");
                await blob.UploadTextAsync(TestData);

                blob = BlobContainer.GetBlockBlobReference("blob3");
                await blob.UploadTextAsync(TestData);

                blob = BlobContainer.GetBlockBlobReference("file1");
                await blob.UploadTextAsync(TestData);

                blob = BlobContainer.GetBlockBlobReference("file2");
                await blob.UploadTextAsync(TestData);

                blob = BlobContainer.GetBlockBlobReference("overwrite");
                await blob.UploadTextAsync(TestData);

                // add a couple hierarchical blob paths
                blob = hierarchicalBlobContainer.GetBlockBlobReference("sub/blob1");
                await blob.UploadTextAsync(TestData);

                blob = hierarchicalBlobContainer.GetBlockBlobReference("sub/blob2");
                await blob.UploadTextAsync(TestData);

                blob = hierarchicalBlobContainer.GetBlockBlobReference("sub/sub/blob3");
                await blob.UploadTextAsync(TestData);

                blob = hierarchicalBlobContainer.GetBlockBlobReference("blob4");
                await blob.UploadTextAsync(TestData);

                byte[] bytes     = new byte[512];
                byte[] testBytes = Encoding.UTF8.GetBytes(TestData);
                for (int i = 0; i < testBytes.Length; i++)
                {
                    bytes[i] = testBytes[i];
                }
                CloudPageBlob pageBlob = pageBlobContainer.GetPageBlobReference("blob1");
                await pageBlob.UploadFromByteArrayAsync(bytes, 0, bytes.Length);

                pageBlob = pageBlobContainer.GetPageBlobReference("blob2");
                await pageBlob.UploadFromByteArrayAsync(bytes, 0, bytes.Length);

                CloudAppendBlob appendBlob = appendBlobContainer.GetAppendBlobReference("blob1");
                await appendBlob.UploadTextAsync(TestData);

                appendBlob = appendBlobContainer.GetAppendBlobReference("blob2");
                await appendBlob.UploadTextAsync(TestData);

                appendBlob = appendBlobContainer.GetAppendBlobReference("blob3");
                await appendBlob.UploadTextAsync(TestData);
            }
        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();

            JobHost host = new JobHost(config);

            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"));

            host.RunAndBlock();
        }