コード例 #1
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;
            }
        }
コード例 #2
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();
        }
コード例 #3
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();
        }
コード例 #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
        public IServiceProvider ConfigureServices(IServiceCollection services)
        //public void ConfigureServices(IServiceCollection services)
        {
            var settings = GeneralSettingsReader.ReadGeneralSettings <BaseSettings>(Configuration,
                                                                                    "OffchainMonitorSettings");

            services.AddMvc(o =>
            {
                o.Filters.Add(new HandleAllExceptionsFilterFactory());
            });

            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new Info {
                    Title = "OffchainMonitor_Api", Version = "v1"
                });
                options.DescribeAllEnumsAsStrings();

                //Determine base path for the application.
                var basePath = PlatformServices.Default.Application.ApplicationBasePath;

                //Set the comments path for the swagger json and ui.
                var xmlPath = Path.Combine(basePath, "OffchainMonitorApi.xml");
                options.IncludeXmlComments(xmlPath);
            });

            var builder = new SqlliteBinder().Bind(settings);

            builder.Populate(services);
            builder.RegisterType <TimerTriggerBinding>();
            builder.RegisterType <QueueTriggerBinding>();
            builder.RegisterType <CommitmentBroadcastCheck>();
            var container   = builder.Build();
            var triggerHost = new TriggerHost(new AutofacServiceProvider(container));

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

            return(new AutofacServiceProvider(container));
        }
コード例 #5
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();
        }
コード例 #6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc()
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.ContractResolver = new DefaultContractResolver();
            });

            services.AddSwaggerGen(options =>
            {
                options.DefaultLykkeConfiguration("v1", "SlackNotifications Job API");
            });

            var builder         = new ContainerBuilder();
            var settingsManager = Configuration.LoadSettings <AppSettings>();

            Log = CreateLogWithSlack(services, settingsManager);
            builder.RegisterInstance(Log).As <ILog>().SingleInstance();

            var settings = settingsManager.CurrentValue;

            builder.RegisterInstance(settings.SlackNotificationsJobSettings).SingleInstance();
            builder.RegisterType <SlackNotifcationsConsumer>();

            if (!string.IsNullOrEmpty(settings.SlackNotificationsJobSettings.ForwardMonitorMessagesQueueConnString))
            {
                builder.RegisterInstance <IMsgForwarder>(new MsgForwarder(AzureQueueExt.Create(
                                                                              settingsManager.ConnectionString(x => x.SlackNotificationsJobSettings.ForwardMonitorMessagesQueueConnString),
                                                                              "slack-notifications-monitor"))).SingleInstance();
            }
            else
            {
                builder.RegisterInstance <IMsgForwarder>(new MsgForwarderStub()).SingleInstance();
            }

            builder.RegisterType <NotificationFilter>().As <INotificationFilter>().SingleInstance();
            builder
            .RegisterType <SrvSlackNotifications>()
            .WithParameter(TypedParameter.From(settings.SlackIntegration))
            .WithParameter(TypedParameter.From(settings))
            .As <ISlackNotificationSender>();
            builder
            .Register(c => MessagesRepository.Create(settingsManager.Nested(s => s.SlackNotificationsJobSettings.FullMessagesConnString)))
            .As <IMessagesRepository>();

            builder.AddTriggers(pool =>
            {
                pool.AddDefaultConnection(settingsManager.ConnectionString(x => x.SlackNotificationsJobSettings.SharedStorageConnString));
            });

            builder.RegisterType <UnmuteHandler>()
            .As <IStartable>()
            .AutoActivate()
            .SingleInstance();

            builder.Populate(services);

            ApplicationContainer = builder.Build();

            var serviceProvider = new AutofacServiceProvider(ApplicationContainer);

            _triggerHost = new TriggerHost(serviceProvider);
            _triggerHost.ProvideAssembly(typeof(SlackNotifcationsConsumer).Assembly);

            return(serviceProvider);
        }