Azure Function Container is disposed and should not be used:容器已处置

Azure Function Container is disposed and should not be used: Container is disposed

我已经设置并配置了 Azure Function v3 (.net core)。这是一个 long-运行ning 过程,调用一些外部 API 并将结果存储在 DB 中。问题是它只完成了 50% 的时间 运行s。其他时候我得到一个例外:

Container is disposed and should not be used: Container is disposed. You may include Dispose stack-trace into the message via: container.With(rules => rules.WithCaptureContainerDisposeStackTrace())

监控日志:

监控日志:

失败:

我应该看什么?当我在本地 运行 它工作正常。 在我的数据挖掘器中,我有这个(异常与 AzureFunction 或我的代码有关)?

public DataMiner(ILogger<DataMiner> logger, IApiClientFactory apiClientFactory, IOptions<DataMinerOptions> options,
    IServiceScopeFactory serviceScopeFactory)
{
    _logger = logger;
    _apiClientFactory = apiClientFactory;
    _options = options.Value;
    _serviceScopeFactory = serviceScopeFactory;
}

public async Task ProcessListingServiceAsync(string listingServiceCode, CancellationToken cancel = default)
{
    using var scope = _serviceScopeFactory.CreateScope();
    var listingServiceRepository = scope.ServiceProvider.GetRequiredService<IRepository<ListingService>>();
    var listingServices = listingServiceRepository.Get(service => service.Enabled);

    
    ...

编辑: 这可能是一个原因吗?说 30 分钟后超时。我确实将功能超时设置为 2 小时。看起来不在考虑范围内:

{
    "version": "2.0",
    "logging": {
        "logLevel": {
            "Functions": "Information"
        },
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            }
        }
    },

    "functionTimeout": "02:00:00"
}

编辑 2: 由于某种原因 host.json 无法加载,有什么想法吗?: 我确实看到 host.json 已加载到我已部署的其他功能中

原来我在我的函数中设置了“runOnStartup”,这是一个非常密集的过程。

    [Singleton]
    [Timeout("02:00:00")]
    [FunctionName("Calculator")]
    public async Task Calculator([TimerTrigger("%CalculatorScheduleTriggerTime%", RunOnStartup = true)] TimerInfo timer)
    {
          .....

这使得我的功能在部署后立即启动,导致我的设置在几分钟后 load/or 无法加载:

runOnStartup RunOnStartup If true, the function is invoked when the runtime starts. For example, the runtime starts when the function app wakes up after going idle due to inactivity. when the function app restarts due to function changes, and when the function app scales out. So runOnStartup should rarely if ever be set to true, especially in production.