Exemplo n.º 1
0
        public void UnHealthilyTest()
        {
            SqlServerHealthCheckOptions options = new SqlServerHealthCheckOptions();

            options.ConnectionString = ConnectionString2;
            options.Sql = "SELECT 1";
            SqlServerHealthCheck healthCheck = new SqlServerHealthCheck(options);
            var response = healthCheck.IsHealthily();

            Assert.True(response.GetType() == typeof(UnHealthilyResponse));
        }
        protected override IJob Build()
        {
            var job = new PipelineJob(Logger, "SqlServerCheck");

            job.RaiseJobExceptionEvent += Job_RaiseJobExceptionEvent;
            var dbServerIP = IPAddress.Parse("127.0.0.1");

            var policy = Policy.Handle <HttpRequestException>().WaitAndRetryAsync(new[]
            {
                TimeSpan.FromSeconds(1),
                TimeSpan.FromSeconds(2),
                TimeSpan.FromSeconds(3)
            });

            job.Use((_) =>
            {
                var sqlQueryCheck = new SqlServerHealthCheck <int>(new DbHealthCheckParams <int>(
                                                                       connectionString: "Server=(localdb)\\mssqllocaldb;Database=WatusiHangfire;Trusted_Connection=True;"
                                                                       , query: "SELECT 1"
                                                                       , decideStatus: r => r == 1?HealthCheckStatus.Healthy:HealthCheckStatus.Unhealthy
                                                                       , notify: (m, r) => Console.WriteLine(m)));
                return(sqlQueryCheck.Beat());
            }, policy)
            .Use((_) =>
            {
                var telnetCheck = new TelnetHealthCheck(new TelnetHealthCheckParams(
                                                            ipAddress: dbServerIP
                                                            , dnsName: null
                                                            , port: 1433
                                                            , retryCount: 3
                                                            , notify: (m, r) => Console.WriteLine(m)));
                return(telnetCheck.Beat());
            }, policy);

            return(job);
        }
Exemplo n.º 3
0
 public AzureSqlHealthChecker(IConfiguration configuration)
 {
     _checker = new SqlServerHealthCheck(configuration["Settings:AzureSql"], "SELECT 1;");
 }