小编res*_*ute的帖子

向 .NET 隔离的 Azure 函数添加运行状况检查

我找不到任何资源来将运行状况检查添加到在 .NET 5.0 隔离中运行的 HTTPTrigger 功能应用程序。

static async Task Main()
{
    var host = new HostBuilder()
        .ConfigureAppConfiguration(configurationBuilder =>
        {
            configurationBuilder.AddEnvironmentVariables();
        })
        .ConfigureFunctionsWorkerDefaults()
        .ConfigureServices((builder, services) =>
        {
            var configuration = builder.Configuration;
            services.AddDbContext(configuration);
                    
            // Add healthcheck here
            services.AddHealthChecks()
            // ...
            // Map health checks
                    
        })
        .Build();

    await host.RunAsync();
}
Run Code Online (Sandbox Code Playgroud)

指南指出我可以添加 MapHealthChecks (但在 asp.net core 中)

var app = builder.Build();

app.MapHealthChecks("/healthz");

app.Run();
Run Code Online (Sandbox Code Playgroud)

如何将其转换为在我的 dotnet 隔离应用程序中运行?

.net azure-functions .net-5 health-check azure-http-trigger

8
推荐指数
1
解决办法
4107
查看次数

在testing.postgresql中,在Docker中找不到initdb命令

有一个类似的线程也有同样的问题,但无法为我工作。基本上,我正在尝试进行单元测试myprojecttesting.postgresql并在 docker 容器内运行它。

但是,RuntimeError: command not found: initdb当我运行命令时,我得到一个,

docker-compose exec myproject python3 -m unittest

这在 WSL 中有效,但在 docker 中无效。

看起来好像找不到 initdb。是否与 docker-compose.yml 中创建的数据库存在冲突问题,或者我是否缺少 docker 文件中的某些行?

我概述了我的测试,例如文档中的示例:

class TestPostgresqlInteraction(unittest.TestCase):

    Postgresql = testing.postgresql.PostgresqlFactory(cache_initialized_db=True)

    with testing.postgresql.Postgresql() as postgresql:
        engine = create_engine(postgresql.url())
        dbConn = psycopg2.connect(**postgresql.dsn())
        cursor = dbConn.cursor()
        def setUp(self):
            self.postgresql = self.Postgresql()

        def tearDown(self):
            self.postgresql.stop()

        def testMethod(self)
            conn = psycopg2.connect(**self.postgresql.dsn())
            cursor = conn.cursor()
            # execute cursor and do tests... 

        def tearDownModule(self):
            self.Postgresql.clear_cache()
Run Code Online (Sandbox Code Playgroud)

docker-compose.yml …

python postgresql unit-testing docker

5
推荐指数
1
解决办法
3013
查看次数