コード例 #1
0
ファイル: Program.cs プロジェクト: LykkeCity/JobTriggers
        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();
                }
            }
        }
コード例 #2
0
        private async Task StartApplication()
        {
            try
            {
                // NOTE: Job not yet recieve and process IsAlive requests here

                await ApplicationContainer.Resolve <IStartupManager>().StartAsync();

#if azurequeuesub
                _triggerHost = new TriggerHost(new AutofacServiceProvider(ApplicationContainer));

                _triggerHostTask = _triggerHost.Start();
#endif
                await Log.WriteMonitorAsync("", Program.EnvInfo, "Started");

#if (!DEBUG)
                await AutoRegistrationInMonitoring.RegisterAsync(Configuration, _monitoringServiceUrl, Log);
#endif
            }
            catch (Exception ex)
            {
                await Log.WriteFatalErrorAsync(nameof(Startup), nameof(StartApplication), "", ex);

                throw;
            }
        }
コード例 #3
0
        public Task StartAsync()
        {
            _cqrsEngine.StartSubscribers();
            _cqrsEngine.StartProcesses();

            TriggerHostTask = _triggerHost.Start();

            return(Task.CompletedTask);
        }
コード例 #4
0
ファイル: AppHost.cs プロジェクト: LykkeCity/TelegramBot
        public void Run()
        {
            var containerBuilder = _binder.Bind(_configurationRoot);
            var ioc = containerBuilder.Build();

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

            triggerHost.Start().Wait();
        }
コード例 #5
0
        public async Task StartAsync()
        {
            foreach (var startable in _startables)
            {
                startable.Start();
            }

            await _triggerHost.Start();
        }
コード例 #6
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();
            }
        }
コード例 #7
0
        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();
            }
        }
コード例 #8
0
ファイル: RoqueService.cs プロジェクト: vmaron/Roque
 protected override void OnStart(string[] args)
 {
     if (_Host == null)
     {
         _Host = new WorkerHost();
     }
     _Host.Start();
     if (_TriggerHost == null)
     {
         _TriggerHost = new TriggerHost();
     }
     _TriggerHost.Start();
 }
コード例 #9
0
        private async Task StartApplication()
        {
            try
            {
                _triggerHostTask = _triggerHost.Start();

                await Log.WriteMonitorAsync("", $"Env: {Program.EnvInfo}", "Started");
            }
            catch (Exception ex)
            {
                await Log.WriteFatalErrorAsync(nameof(Startup), nameof(StartApplication), ex);
            }
        }
コード例 #10
0
ファイル: Program.cs プロジェクト: LykkeCity/SolarCoinApi
        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
            }
        }
コード例 #11
0
        private async Task StartApplication()
        {
            try
            {
                _triggerHost = new TriggerHost(new AutofacServiceProvider(ApplicationContainer));

                _triggerHostTask = _triggerHost.Start();
                await Log.WriteMonitorAsync("", Program.EnvInfo, "Started");
            }
            catch (Exception ex)
            {
                await Log.WriteFatalErrorAsync(nameof(Startup), nameof(StartApplication), "", ex);

                throw;
            }
        }
コード例 #12
0
ファイル: RoqueApp.cs プロジェクト: vmaron/Roque
        private static void Work([CLAP.Description("worker to start, or none to start all")] string worker)
        {
            var host = new WorkerHost();

            host.Start(worker);
            var triggerHost = new TriggerHost();

            triggerHost.Start();
            Console.WriteLine();
            Console.WriteLine("PRESS ANY KEY TO STOP");
            Console.WriteLine();
            Console.ReadKey(true);
            host.Stop();
            triggerHost.Stop();
            Console.WriteLine("Goodbye!");
        }
コード例 #13
0
        private void StartApplication()
        {
            try
            {
                _triggerHost = new TriggerHost(new AutofacServiceProvider(ApplicationContainer));

                _triggerHostTask = _triggerHost.Start();
            }
            catch (Exception ex)
            {
                Log?.WriteFatalErrorAsync(nameof(Startup), nameof(StartApplication), "", ex);
                if (Log == null)
                {
                    Console.WriteLine(ex);
                }
            }
        }
コード例 #14
0
        private async Task StartApplication()
        {
            try
            {
                // NOTE: Job not yet recieve and process IsAlive requests here
                
                _triggerHost = new TriggerHost(new AutofacServiceProvider(ApplicationContainer));
                _triggerHost.ProvideAssembly(GetType().GetTypeInfo().Assembly);
                _triggerHostTask = _triggerHost.Start();

                await Log.WriteMonitorAsync("", "", "Started");
            }
            catch (Exception ex)
            {
                await Log.WriteFatalErrorAsync(nameof(Startup), nameof(StartApplication), "", ex);
                throw;
            }
        }
コード例 #15
0
        private async Task StartApplication()
        {
            try
            {
                var cqrs = ApplicationContainer.Resolve <ICqrsEngine>(); // bootstrap

                _triggerHost     = new TriggerHost(new AutofacServiceProvider(ApplicationContainer));
                _triggerHostTask = _triggerHost.Start();

                await Log.WriteMonitorAsync("", "", "Started");
            }
            catch (Exception ex)
            {
                await Log.WriteFatalErrorAsync(nameof(Startup), nameof(StartApplication), "", ex);

                throw;
            }
        }
コード例 #16
0
ファイル: Startup.cs プロジェクト: LykkeCity/BCNReports
        private async Task StartApplication()
        {
            try
            {
                // NOTE: Service not yet recieve and process requests here
                _triggerHost = new TriggerHost(new AutofacServiceProvider(ApplicationContainer));

                _triggerHostTask = _triggerHost.Start();
                await ApplicationContainer.Resolve <IStartupManager>().StartAsync();

                await Log.WriteInfoAsync("", "", "Started");
            }
            catch (Exception ex)
            {
                await Log.WriteFatalErrorAsync(nameof(Startup), nameof(StartApplication), "", ex);

                throw;
            }
        }
コード例 #17
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();
        }
コード例 #18
0
        private async Task StartApplication()
        {
            try
            {
                // NOTE: Job not yet recieve and process IsAlive requests here
#if !DEBUG
                await Configuration.RegisterInMonitoringServiceAsync(_monitoringServiceUrl, _healthNotifier);
#endif
                _triggerHost = new TriggerHost(new AutofacServiceProvider(ApplicationContainer));

                _triggerHostTask = _triggerHost.Start();
                _healthNotifier.Notify("Started", Program.EnvInfo);
            }
            catch (Exception ex)
            {
                _log.Critical(ex);
                throw;
            }
        }
コード例 #19
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();
        }
コード例 #20
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
            }
        }
コード例 #21
0
ファイル: Program.cs プロジェクト: LykkeCity/SolarCoinApi
        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
            }
        }
コード例 #22
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();
        }
コード例 #23
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();
        }
コード例 #24
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");
        }
コード例 #25
0
ファイル: RoqueApp.cs プロジェクト: carcer/Roque
 private static void Work([CLAP.Description("worker to start, or none to start all")]string worker)
 {
     var host = new WorkerHost();
     host.Start(worker);
     var triggerHost = new TriggerHost();
     triggerHost.Start();
     Console.WriteLine();
     Console.WriteLine("PRESS ANY KEY TO STOP");
     Console.WriteLine();
     Console.ReadKey(true);
     host.Stop();
     triggerHost.Stop();
     Console.WriteLine("Goodbye!");
 }
コード例 #26
0
 public async Task StartAsync()
 {
     await _triggerHost.Start();
 }