Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            using (var logFactory = LogFactory.Create().AddUnbufferedConsole())
            {
                var builder = new ContainerBuilder();

                builder.RegisterInstance(logFactory);

                builder.AddTriggers(pool =>
                {
                    pool.AddDefaultConnection(new FakeReloadingManager("UseDevelopmentStorage=true"));
                });

                builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());

                using (var container = builder.Build())
                {
                    var host = new TriggerHost(new AutofacServiceProvider(container));
                    var task = host.Start();

                    Console.ReadKey();
                    host.Cancel();
                    task.Wait();
                    Console.ReadKey();
                }
            }
        }
Ejemplo n.º 2
0
        private async Task StopApplication()
        {
            try
            {
                // NOTE: Job still can recieve and process IsAlive requests here, so take care about it if you add logic here.

                await ApplicationContainer.Resolve <IShutdownManager>().StopAsync();

#if azurequeuesub
                _triggerHost?.Cancel();

                if (_triggerHostTask != null)
                {
                    await _triggerHostTask;
                }
#endif
            }
            catch (Exception ex)
            {
                if (Log != null)
                {
                    await Log.WriteFatalErrorAsync(nameof(Startup), nameof(StopApplication), "", ex);
                }
                throw;
            }
        }
        public async Task StopAsync()
        {
            _triggerHost.Cancel();

            if (StartupManager.TriggerHostTask != null)
            {
                await StartupManager.TriggerHostTask;
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
#if DEBUG
            Console.WriteLine("Starting... Is DEBUG");
#else
            Console.WriteLine("Starting... Is RELEASE");
#endif

            var         webHostCancellationTokenSource = new CancellationTokenSource();
            IWebHost    webHost         = null;
            TriggerHost triggerHost     = null;
            Task        webHostTask     = null;
            Task        triggerHostTask = null;
            var         end             = new ManualResetEvent(false);

            try
            {
                AssemblyLoadContext.Default.Unloading += ctx =>
                {
                    Console.WriteLine("SIGTERM recieved");

                    webHostCancellationTokenSource.Cancel();

                    end.WaitOne();
                };

                webHost = new WebHostBuilder()
                          .UseKestrel()
                          .UseUrls("http://*:5000")
                          .UseContentRoot(Directory.GetCurrentDirectory())
                          .UseStartup <Startup>()
                          .UseApplicationInsights()
                          .Build();

                triggerHost = new TriggerHost(webHost.Services);

                webHostTask     = webHost.RunAsync(webHostCancellationTokenSource.Token);
                triggerHostTask = triggerHost.Start();

                // WhenAny to handle any task termination with exception,
                // or gracefully termination of webHostTask
                Task.WhenAny(webHostTask, triggerHostTask).Wait();
            }
            finally
            {
                Console.WriteLine("Terminating...");

                webHostCancellationTokenSource.Cancel();
                triggerHost?.Cancel();

                webHostTask?.Wait();
                triggerHostTask?.Wait();

                end.Set();
            }
        }
        static void Main(string[] args)
        {
            var         webHostCancellationTokenSource = new CancellationTokenSource();
            IWebHost    webHost         = null;
            TriggerHost triggerHost     = null;
            Task        webHostTask     = null;
            Task        triggerHostTask = null;
            var         end             = new ManualResetEvent(false);

            try
            {
                AssemblyLoadContext.Default.Unloading += ctx =>
                {
                    Console.WriteLine("SIGTERM recieved");

                    webHostCancellationTokenSource.Cancel();

                    end.WaitOne();
                };

                webHost = new WebHostBuilder()
                          .UseKestrel()
                          .UseUrls("http://*:5000")
                          .UseContentRoot(Directory.GetCurrentDirectory())
                          .UseStartup <Startup>()
                          .UseApplicationInsights()
                          .Build();

                var version = typeof(Program).GetTypeInfo().Assembly.GetCustomAttribute <AssemblyFileVersionAttribute>().Version;
                Console.WriteLine($"Build Version {version}");

                triggerHost = new TriggerHost(webHost.Services);

                webHostTask     = Task.Factory.StartNew(() => webHost.Run());
                triggerHostTask = triggerHost.Start();

                // WhenAny to handle any task termination with exception,
                // or gracefully termination of webHostTask
                Task.WhenAny(webHostTask, triggerHostTask).Wait();
            }
            finally
            {
                Console.WriteLine("Terminating...");

                webHostCancellationTokenSource.Cancel();
                triggerHost?.Cancel();

                webHostTask?.Wait();
                triggerHostTask?.Wait();

                end.Set();
            }
        }
Ejemplo n.º 6
0
        public static void Main(string[] args)
        {
            try
            {
                Console.Title = "SolarCoin CashOut job";

#if DEBUG
                var settings = new AppSettings <CashOutSettings>().LoadFile("appsettings.Debug.json");
#elif RELEASE
                var settings = new AppSettings <CashOutSettings>().LoadFromWeb(Environment.GetEnvironmentVariable("SlrSettingsUrl")).Result;
                settings.HotWalletPrivKey = Environment.GetEnvironmentVariable("HotWalletPrivateKey");
#endif

                ServiceProvider = new AutofacServiceProvider(Bootstrap.ConfigureBuilder(ComponentName, settings).Build());

                var rpcClient = ServiceProvider.GetService <IJsonRpcClient>();

                Console.WriteLine("Importing private key to the local node - this may take up to several minutes...");

                rpcClient.ImportPrivateKey(settings.HotWalletPrivKey).GetAwaiter().GetResult();

                Console.WriteLine("The key was imported!");

                TriggerHost = new TriggerHost(ServiceProvider);

                AssemblyLoadContext.Default.Unloading += ctx =>
                {
                    Console.WriteLine("SIGTERM recieved");

                    TriggerHost.Cancel();
                };

                TriggerHost.Start().GetAwaiter().GetResult();
            }
            catch (Exception e)
            {
                TriggerHost?.Cancel();

                Task.Delay(1000).GetAwaiter().GetResult();

                ServiceProvider?.GetService <ILog>()?.WriteErrorAsync(ComponentName, "", "", e).GetAwaiter().GetResult();

                e.PrintToConsole();
#if DEBUG
                Console.ReadKey();
#endif
            }
        }
Ejemplo n.º 7
0
 private async Task StopApplication()
 {
     try
     {
         _triggerHost?.Cancel();
         _triggerHostTask?.Wait();
     }
     catch (Exception ex)
     {
         if (Log != null)
         {
             await Log.WriteFatalErrorAsync(nameof(Startup), nameof(StopApplication), "", ex);
         }
         throw;
     }
 }
Ejemplo n.º 8
0
        public async Task StopAsync()
        {
#if azurequeuesub
            _triggerHost.Cancel();
#endif
            try
            {
                await Task.WhenAll(_stoppables.Select(i => Task.Run(() => i.Stop())));

                await Task.WhenAll(_items.Select(i => Task.Run(() => i.Stop())));
            }
            catch (Exception ex)
            {
                _log.Warning($"Unable to stop a component", ex);
            }
        }
Ejemplo n.º 9
0
        private async Task StopApplication()
        {
            try
            {
                _triggerHost?.Cancel();

                if (_triggerHostTask != null)
                {
                    await _triggerHostTask;
                }
            }
            catch (Exception ex)
            {
                _log?.Critical(ex);
                throw;
            }
        }
Ejemplo n.º 10
0
 private async Task StopApplication()
 {
     try
     {
         // NOTE: Job still can recieve and process IsAlive requests here, so take care about it if you add logic here.
         
         _triggerHost?.Cancel();
         await _triggerHostTask;
     }
     catch (Exception ex)
     {
         if (Log != null)
         {
             await Log.WriteFatalErrorAsync(nameof(Startup), nameof(StopApplication), "", ex);
         }
         throw;
     }
 }
Ejemplo n.º 11
0
 private async Task StopApplication()
 {
     try
     {
         // NOTE: Service still can recieve and process requests here, so take care about it if you add logic here.
         _triggerHost?.Cancel();
         _triggerHostTask?.Wait();
         await ApplicationContainer.Resolve <IShutdownManager>().StopAsync();
     }
     catch (Exception ex)
     {
         if (Log != null)
         {
             await Log.WriteFatalErrorAsync(nameof(Startup), nameof(StopApplication), "", ex);
         }
         throw;
     }
 }
Ejemplo n.º 12
0
        private void StopApplication()
        {
            try
            {
                // TODO: Implement your shutdown logic here.
                // Job still can recieve and process IsAlive requests here, so take care about it.

                _triggerHost?.Cancel();
                _triggerHostTask?.Wait();
            }
            catch (Exception ex)
            {
                Log?.WriteFatalErrorAsync(nameof(Startup), nameof(StopApplication), "", ex);
                if (Log == null)
                {
                    Console.WriteLine(ex);
                }
            }
        }
Ejemplo n.º 13
0
        public void RunJobs()
        {
            var triggerHost = new TriggerHost(Services);

            triggerHost.ProvideAssembly(GetType().GetTypeInfo().Assembly);

            var end = new ManualResetEvent(false);

            AssemblyLoadContext.Default.Unloading += ctx =>
            {
                Console.WriteLine("SIGTERM recieved");
                triggerHost.Cancel();

                end.WaitOne();
            };

            triggerHost.Start().Wait();
            end.Set();
        }
        public async Task StopAsync()
        {
            // TODO: Implement your shutdown logic here. Good idea is to log every step
            foreach (var item in _items)
            {
                try
                {
                    item.Stop();
                }
                catch (Exception ex)
                {
                    _log.Warning($"Unable to stop {item.GetType().Name}", ex);
                }
            }

#if azurequeuesub
            _triggerHost.Cancel();
#endif
            await Task.CompletedTask;
        }
Ejemplo n.º 15
0
        public void Run()
        {
            // Load settings
            var settingsUrl = Configuration["SettingsUrl"];

            if (string.IsNullOrWhiteSpace(settingsUrl))
            {
                // Environment variable "SettingsUrl" with URL to settings file (e.g. "https://settings-dev.lykkex.net/xJNaS5XHZg6DfuUccyKfNcSiiIPMzM1E_WithdrawalRequestScheduler") should exist
                // You can do that at Project's properties -> Debug -> Environment Variables

                Console.WriteLine($"''SettingsUrl'' environment variable empty or not found");
                return;
            }

            var httpClient     = new HttpClient();
            var response       = httpClient.GetAsync(settingsUrl).Result;
            var settingsString = response.Content.ReadAsStringAsync().Result;
            var settings       = Newtonsoft.Json.JsonConvert.DeserializeObject <AppSettings>(settingsString);


            var containerBuilder = new AzureBinder().Bind(settings.Settings);
            var ioc = containerBuilder.Build();

            var triggerHost = new TriggerHost(new AutofacServiceProvider(ioc));

            triggerHost.ProvideAssembly(GetType().GetTypeInfo().Assembly);

            var end = new ManualResetEvent(false);

            AssemblyLoadContext.Default.Unloading += ctx =>
            {
                Console.WriteLine("SIGTERM recieved");
                triggerHost.Cancel();

                end.WaitOne();
            };

            triggerHost.Start().Wait();
            end.Set();
        }
Ejemplo n.º 16
0
        public static void Main(string[] args)
        {
            try
            {
                Console.Title = "SolarCoin CashIn Handler job";

#if DEBUG
                var settings = new AppSettings <CashInHandlerSettings>().LoadFile("appsettings.Debug.json");
#elif RELEASE
                var settings = new AppSettings <CashInHandlerSettings>().LoadFromWeb(Environment.GetEnvironmentVariable("SlrSettingsUrl")).Result;
#endif

                ServiceProvider = new AutofacServiceProvider(Bootrsrap.ConfigureBuilder(ComponentName, settings).Build());

                TriggerHost = new TriggerHost(ServiceProvider);

                AssemblyLoadContext.Default.Unloading += ctx =>
                {
                    Console.WriteLine("SIGTERM recieved");

                    TriggerHost.Cancel();
                };

                TriggerHost.Start().GetAwaiter().GetResult();
            }
            catch (Exception e)
            {
                TriggerHost?.Cancel();

                Task.Delay(1000).GetAwaiter().GetResult();

                ServiceProvider?.GetService <ILog>()?.WriteErrorAsync(ComponentName, "", "", e).GetAwaiter().GetResult();

                e.PrintToConsole();
#if DEBUG
                Console.ReadKey();
#endif
            }
        }
Ejemplo n.º 17
0
        private async Task StopApplication()
        {
            try
            {
                await ApplicationContainer.Resolve <IShutdownManager>().StopAsync();

                _triggerHost?.Cancel();

                if (_triggerHostTask != null)
                {
                    await _triggerHostTask;
                }
            }
            catch (Exception ex)
            {
                if (Log != null)
                {
                    await Log.WriteFatalErrorAsync(nameof(Startup), nameof(StopApplication), "", ex);
                }
                throw;
            }
        }
Ejemplo n.º 18
0
        public static void Main(string[] args)
        {
            try
            {
#if DEBUG
                var settings = new AppSettings <AlertsSettings>().LoadFile("appsettings.Debug.json");
#elif RELEASE
                var settings = new AppSettings <AlertsSettings>().LoadFromEnvironment();
#endif
                BsonClassMap.RegisterClassMap <TransactionMongoEntity>();

                ServiceProvider = new AutofacServiceProvider(Bootstrap.ConfigureBuilder(ComponentName, settings).Build());

                TriggerHost = new TriggerHost(ServiceProvider);

                AssemblyLoadContext.Default.Unloading += ctx =>
                {
                    Console.WriteLine("SIGTERM recieved");

                    TriggerHost.Cancel();
                };


                TriggerHost.Start().GetAwaiter().GetResult();
            }
            catch (Exception e)
            {
                TriggerHost?.Cancel();

                ServiceProvider?.GetService <ILog>()?.WriteErrorAsync(ComponentName, "", "", e).GetAwaiter().GetResult();

                e.PrintToConsole();
#if DEBUG
                Console.ReadKey();
#endif
            }
        }
Ejemplo n.º 19
0
        public void Run()
        {
            var settings = GeneralSettingsReader.ReadGeneralSettings <GeneralSettings>(Configuration.GetConnectionString("Settings"));

            var containerBuilder = new AzureBinder().Bind(settings.ChronobankJobs);
            var ioc = containerBuilder.Build();

            var triggerHost = new TriggerHost(new AutofacServiceProvider(ioc));

            triggerHost.ProvideAssembly(GetType().GetTypeInfo().Assembly);

            var end = new ManualResetEvent(false);

            AssemblyLoadContext.Default.Unloading += ctx =>
            {
                Console.WriteLine("SIGTERM recieved");
                triggerHost.Cancel();

                end.WaitOne();
            };

            triggerHost.Start().Wait();
            end.Set();
        }
Ejemplo n.º 20
0
        public static void Main(string[] args)
        {
            ContainerBuilder builder = new ContainerBuilder();

            ILog log = new LogToConsole();

            builder.RegisterInstance(log);

            builder.AddTriggers(pool =>
            {
                pool.AddDefaultConnection("UseDevelopmentStorage=true");
            });

            builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
            var container = builder.Build();

            var host = new TriggerHost(new AutofacServiceProvider(container));
            var task = host.Start();

            Console.ReadKey();
            host.Cancel();
            task.Wait();
            Console.ReadKey();
        }
Ejemplo n.º 21
0
        public static async Task Main(string[] args)
        {
            Console.WriteLine($"Lykke.Job.ServicesMonitoring version {Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationVersion}");
#if DEBUG
            Console.WriteLine("Is DEBUG");
#else
            Console.WriteLine("Is RELEASE");
#endif
            Console.WriteLine($"ENV_INFO: {EnvInfo}");

            var         webHostCancellationTokenSource = new CancellationTokenSource();
            IWebHost    webHost         = null;
            TriggerHost triggerHost     = null;
            Task        webHostTask     = null;
            Task        triggerHostTask = null;
            var         end             = new ManualResetEvent(false);

            try
            {
                AssemblyLoadContext.Default.Unloading += ctx =>
                {
                    Console.WriteLine("SIGTERM recieved");

                    webHostCancellationTokenSource.Cancel();

                    end.WaitOne();
                };

                webHost = new WebHostBuilder()
                          .UseKestrel()
                          .UseUrls("http://*:5000")
                          .UseContentRoot(Directory.GetCurrentDirectory())
                          .UseStartup <Startup>()
                          .UseApplicationInsights()
                          .Build();

                triggerHost = new TriggerHost(webHost.Services);

                webHostTask     = webHost.RunAsync(webHostCancellationTokenSource.Token);
                triggerHostTask = triggerHost.Start();

                // WhenAny to handle any task termination with exception,
                // or gracefully termination of webHostTask
                Task.WhenAny(webHostTask, triggerHostTask).Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Fatal error:");
                Console.WriteLine(ex);

                // Lets devops to see startup error in console between restarts in the Kubernetes
                var delay = TimeSpan.FromMinutes(1);

                Console.WriteLine();
                Console.WriteLine($"Process will be terminated in {delay}. Press any key to terminate immediately.");

                await Task.WhenAny(
                    Task.Delay(delay),
                    Task.Run(() =>
                {
                    Console.ReadKey(true);
                }));
            }
            finally
            {
                Console.WriteLine("Terminating...");

                webHostCancellationTokenSource.Cancel();
                triggerHost?.Cancel();

                webHostTask?.Wait();
                triggerHostTask?.Wait();

                end.Set();
            }

            Console.WriteLine("Terminated");
        }