Reputation: 21328
I have set up and configured Azure Function v3 (.net core). It is a long-running process that calls some external API and stores the result in DB. The problem is that it only completes 50% of the time it runs. Other times I get an exception:
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())
Monitor log:
What should I be looking at? It works fine when I run it locally. In my data miner, I have this (is the exception related to AzureFunction or my code)?
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);
...
EDIT: could this be a reason? Says timeout after 30 min. I did set function timeout to 2 hours. Looks like it's not being considered:
{
"version": "2.0",
"logging": {
"logLevel": {
"Functions": "Information"
},
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"functionTimeout": "02:00:00"
}
EDIT 2: For some reason host.json is not able to load, any ideas?: I do see host.json loaded in my other functions that I have deployed
Upvotes: 1
Views: 3171
Reputation: 21328
Turns out I had "runOnStartup" set in my Function which is a pretty intensive process.
[Singleton]
[Timeout("02:00:00")]
[FunctionName("Calculator")]
public async Task Calculator([TimerTrigger("%CalculatorScheduleTriggerTime%", RunOnStartup = true)] TimerInfo timer)
{
.....
This made my function fire off right away after deployment, causing my settings not to load/or load after few minutes:
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.
Upvotes: 2