6

我是 Hangfire 的新手,所以可能我在某个地方搞砸了。我的 Hangfire 配置如下:https ://github.com/HangfireIO/Hangfire#installation

但不是:

 config.UseSqlServerStorage("<connection string or its name>");

我有:

 config.UsePostgreSqlStorage("Server=127.0.0.1;Port=5432;User Id=postgres;Password=pwd;Database=Hangfire");

所以我在我的数据库中创建了一个 Hangfire 数据库。

然后,我正在构建和运行我的项目。没关系。在我的 postgres 中创建 Hangfire DB 中的所有表。它工作得很好。

但是,当我尝试时:

   BackgroundJob.Enqueue(() => HubService.SendPushNotificationToUsers(threadParticipants,  messageApi.SenderId, messageApi.SenderName, messageApi.ThreadId, messageApi.Content));

我收到 InnerMessage 异常:

  "Timeout while getting a connection from pool." postgres

我错过了什么吗?

4

2 回答 2

3

尝试通过 ConnectionString 或 String Builder 关闭连接池。

这是我们如何做到的

        var sb = new NpgsqlConnectionStringBuilder(connectionString);
        sb.Pooling = false;
        app.UseHangfire(config =>
        {
            config.UseActivator(new WindsorJobActivator(container.Kernel));
            config.UsePostgreSqlStorage(sb.ToString(), new PostgreSqlStorageOptions() { UseNativeDatabaseTransactions = true });
            config.UseServer();
        });
于 2015-03-03T06:30:51.480 回答
2

您是否尝试减少 HangFire 工作人员的数量?也许这些正在消耗您的连接池,因为 Hangfire 默认使用 20 个工作人员 * X 个连接(不记得有多少,但它们是几个),这可能正在消耗您的连接池......因此连接超时......

您可以设置要在hangfire 初始化中使用多少个worker。在此示例中,您将仅使用 1 个工人...

app.UseHangfire(config =>
{
    config.UseServer(1);
});
于 2015-09-14T16:01:38.320 回答