Ejemplo n.º 1
0
        static void Main()
        {
            Task task;
            try
            {
                Database.SetInitializer<ApplicationDbContext>(
                   new MigrateDatabaseToLatestVersion<ApplicationDbContext,
                      Altostratus.DAL.Migrations.Configuration>());
                Exception _lastException = null;

                JobHostConfiguration jobConfig = new JobHostConfiguration();
                jobConfig.DashboardConnectionString = GetAppSecret("AzureWebJobsDashboard");
                jobConfig.StorageConnectionString = GetAppSecret("AzureWebJobsStorage");
                var host = new JobHost(jobConfig);

                // Have to wait for each function to complete before the next one starts because they use an EF 
                // context, and the context isn't thread-safe.
                try
                {
                    task = host.CallAsync(typeof(Functions).GetMethod("GetThreadsAsync"), new { providerName = "Twitter" });
                    task.Wait();
                }
                catch (Exception ex)
                {
                    _lastException = ex;
                }
                try
                {
                    task = host.CallAsync(typeof(Functions).GetMethod("GetThreadsAsync"), new { providerName = "StackOverflow" });
                    task.Wait();
                }
                catch (Exception ex)
                {
                    _lastException = ex;
                }

                task = host.CallAsync(typeof(Functions).GetMethod("PurgeOldThreadsAsync"), new { providerName = "" });
                task.Wait();
                if (_lastException != null)
                {
                    throw _lastException;
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Exception: {0}\n{1}", ex.Message, ex.StackTrace);
                throw;
            }
        }
Ejemplo n.º 2
0
 static void Main()
 {
     using (var host = new JobHost(new JobHostConfiguration
     {
         DashboardConnectionString = Configurations.StorageConnectionString,
         StorageConnectionString = Configurations.StorageConnectionString
     }))
     {
         var task = host.CallAsync(typeof(Functions).GetMethod("ProcessSensorsState"));
         host.RunAndBlock();
     }
 }
        static void Main()
        {
            CreateDemoData();

            JobHost host = new JobHost();
            Task callTask = host.CallAsync(typeof(Functions).GetMethod("ManualTrigger"));
            
            Console.WriteLine("Waiting for async operation...");
            callTask.Wait();
            Console.WriteLine("Task completed: " + callTask.Status);

            host.RunAndBlock();
        }
Ejemplo n.º 4
0
 private static Task ListenForEvent(JobHost host, string partition, CancellationToken cancelToken)
 {
     return Task.Run(() =>
     {
         Console.WriteLine("Start listener for partition '{0}'", partition);
         var eventHubReceiver = _eventHubClient.GetDefaultConsumerGroup().CreateReceiver(partition, DateTime.Now);
         while (true)
         {
             var eventDataTask = eventHubReceiver.ReceiveAsync();
             eventDataTask.Wait(cancelToken);
             if (cancelToken.IsCancellationRequested)
             {
                 cancelToken.ThrowIfCancellationRequested();
             }
             var eventData = eventDataTask.Result;
             if (eventData == null) continue;
             host.CallAsync(typeof(Program).GetMethod("ProcessMessage"), new { eventData, partition }, cancelToken);
         }
     }, cancelToken);
 }
Ejemplo n.º 5
0
 // Please set the following connection strings in app.config for this WebJob to run:
 // AzureWebJobsDashboard and AzureWebJobsStorage
 static void Main()
 {
     var host = new JobHost();
     host.CallAsync(typeof(Functions).GetMethod("ListenForTweetsAsync"));
     host.RunAndBlock();
 }