Пример #1
0
        // 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();
            if (config.IsDevelopment)
            {
                config.UseDevelopmentSettings();
            }

            Console.WriteLine("Starting WebJob");
            _engine = new InitializationEngine((IEnumerable <IInitializableModule>)null, HostType.WebApplication, new AssemblyList(true).AllowedAssemblies);
            Console.WriteLine("Episerver Initialization");
            _engine.Initialize();

            var cancellationToken = new WebJobsShutdownWatcher().Token;

            cancellationToken.Register(() =>
            {
                Console.WriteLine("Episerver Uninitialization");
                _engine.Uninitialize();
            });

            var host = new JobHost(config);

            // The following code ensures that the WebJob will be running continuously
            host.RunAndBlock();
        }
Пример #2
0
        // https://github.com/Azure/azure-webjobs-sdk/issues/1940
        // https://github.com/Azure/azure-webjobs-sdk/issues/2088

        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage
        private static async Task Main()
        {
            var builder = new HostBuilder();

            builder.ConfigureWebJobs(b =>
            {
                b.AddAzureStorageCoreServices();
                b.AddAzureStorage();
                //b.AddTimers();
            });
            var host = builder.Build();

            var cancellationToken = new WebJobsShutdownWatcher().Token;

            cancellationToken.Register(() =>
            {
                host.Services.GetService <IJobHost>().StopAsync();
                // bye bye
            });

            using (host)
            {
                await host.StartAsync(cancellationToken);

                var jobHost = host.Services.GetService <IJobHost>();

                await jobHost.CallAsync(nameof(Functions.LongRunningContinuousProcess),
                                        cancellationToken : cancellationToken);
            }
        }
Пример #3
0
        // Please set the following connection strings in app.config for this WebJob to run:
        // AzureWebJobsDashboard and AzureWebJobsStorage
        static void Main()
        {
            var config = new JobHostConfiguration();

            if (config.IsDevelopment)
            {
                config.UseDevelopmentSettings();
            }

            var host = new JobHost(config);

            var cancellationToken = new WebJobsShutdownWatcher().Token;

            cancellationToken.Register(async() =>
            {
                try
                {
                    Console.WriteLine("-----" + "Shutdown started");
                    for (int i = 0; i < 30; i++)
                    {
                        Console.WriteLine(i);
                        await Task.Delay(1000);
                    }
                    Console.WriteLine("------" + "Shutdown complete");
                    host.Stop();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                }
            });

            // The following code ensures that the WebJob will be running continuously
            host.RunAndBlock();
        }
Пример #4
0
        public static async Task Main(string[] args)
        {
            Console.WriteLine($"{nameof(WebJob)} started");
            var cancellationToken = new WebJobsShutdownWatcher().Token;

            cancellationToken.Register(() =>
            {
                Console.WriteLine("Cancellation received");
                host.Stop();
            });
            // Assuming you want to get your shitty code up in the cloud ASAP
            // so I've created this minimalistic config
            var jobHostConfig = new JobHostConfiguration
            {
                HostId = Guid.NewGuid().ToString("N"),
                StorageConnectionString   = string.Empty,
                DashboardConnectionString = string.Empty
            };

            host = new JobHost(jobHostConfig);
            await host.CallAsync(nameof(OneTimeTask));

            Console.WriteLine($"{nameof(WebJob)} terminated");
        }
Пример #5
0
        /// <summary>
        /// Execute a job with some arguments
        /// </summary>
        /// <param name="verbose"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        static int ExecuteJob(bool verbose, string[] args)
        {
            // Check if a parameter is defined

            switch (args.Length)
            {
            case 0:
                Info("Running Web jobs ...");

                // WebJob is running if and only if the application has a connection string to a storage account into azure environment

                string connectionString = ConfigurationManager.ConnectionStrings[ConfigurationManager.CONNEXION_STRING_AZURE]?.ConnectionString;
                if (String.IsNullOrWhiteSpace(connectionString))
                {
                    break;
                }

                // Run a function on terminating the application by the webjob process

                System.Threading.CancellationToken cancellationToken = new WebJobsShutdownWatcher().Token;
                cancellationToken.Register(() => {
                    // The process is correctly done ...
                    // This notification is raised on closing the web jobs
                    OnClose();
                });

                // Run WebJob in continuous mode

                JobHostConfiguration config = new JobHostConfiguration();
                if (config.IsDevelopment)
                {
                    config.UseDevelopmentSettings();
                }

                config.UseTimers();

                var host = new JobHost(config);
                host.RunAndBlock();
                return(0);

            case 1:
                Info("Running test ...");

                // run a module without any function

                switch (args[0])
                {
                case "Test":
                    return((new Syncytium.WebJob.Module.Test.Job()).Run(verbose, args.RemoveAt(0, 1)));
                }
                break;

            default:
                // run a module within a function

                switch (args[0])
                {
                case Syncytium.Module.Administration.DatabaseContext.AREA_NAME:
                    break;

                case Syncytium.Module.Customer.DatabaseContext.AREA_NAME:
                    break;
                }
                break;
            }

            Usage(args);
            return(-1);
        }