What is the reason for host lock lease acquired by instance id in Azure function?
Asked Answered
B

4

9

I'm running a project which has Azure function, but it's not running my azure function. I have put the breakpoint, its also not hitting the breakpoint. Also, the output is not clear so that I can debug my code. Is there any way to debug the code to find the root cause of the issue?

Output:

[3/20/2018 9:39:31 AM] Reading host configuration file 'C:\Users\myname\Source\MyProject\aspnet-core\src\Nec.MyProject.Processors\bin\Debug\netstandard2.0\host.json' [3/20/2018 9:39:31 AM] Host configuration file read: [3/20/2018 9:39:31 AM] { [3/20/2018 9:39:31 AM] "queues": { [3/20/2018 9:39:31 AM] "maxPollingInterval": 1000, [3/20/2018 9:39:31 AM]
"visibilityTimeout": "00:00:00", [3/20/2018 9:39:31 AM]
"batchSize": 1, [3/20/2018 9:39:31 AM] "maxDequeueCount": 5 [3/20/2018 9:39:31 AM] } [3/20/2018 9:39:31 AM] } [3/20/2018 9:39:48 AM] Generating 15 job function(s) [3/20/2018 9:39:48 AM] Starting Host (HostId=windowsmyname-655615619, Version=2.0.11415.0, ProcessId=6320, Debug=False, ConsecutiveErrors=0, StartupCount=1, FunctionsExtensionVersion=) [3/20/2018 9:39:49 AM] Found the following functions: [3/20/2018 9:39:49 AM] MyCompany.MyProject.Processors.BackOfficeFilesGeneratorJobs.RunTestGeneratorAsync [3/20/2018 9:39:49 AM] [3/20/2018 9:39:49 AM] Job host started Listening on http://localhost:7071/ Hit CTRL-C to exit... [3/20/2018 9:39:50 AM] Host lock lease acquired by instance ID '000000000000000000000000C78D3496'.

Azure Function:

[FunctionName("GenerateTestOfficeMasterDataFiles")]
public static async Task RunTestGeneratorAsync(
    [QueueTrigger("%MasterDataFiles:Supplier:QueueName%", Connection = "ConnectionStrings:BlobStorageAccount")] BackOfficeFileGeneratorMessage<string> message,
    ExecutionContext context,
    TraceWriter log)

Note: It was working fine when it was BackOfficeFileGeneratorMessage instead of BackOfficeFileGeneratorMessage<string>.

Update:

public class BackOfficeFileGeneratorMessage<TEntityKey>
{
    public BackOfficeFileGeneratorMessage()
    {
        Items = new MasterDataFileOperationItem <TEntityKey>[0];
    }
    public bool UseStaging { get; set; }
    public string StoreNo { get; set; }
    public bool RefreshAll { get; set; }
    public IEnumerable<MasterDataFileOperationItem <TEntityKey>> Items { get; set; }
}
Byre answered 20/3, 2018 at 12:8 Comment(1)
do you have messages in the queue you're triggering on?Caecum
C
2

Functions runtime acquires lease on the storage account attached to the function app using an unique Id that is specific to your function App. This is an internal implementation detail.

Deserializing to a generic type should work as long as the queue trigger data matches the POCO. For e.g, here is generic type

public class GenericInput<T>
{
    public T OrderId { get; set; }

    public T CustomerName { get; set; }
}

and the function

 public static void ProcessQueueMessage([QueueTrigger("queuea")] GenericInput<string> message, TextWriter log)
    {
        log.WriteLine(message);
    }

Sample queue data

{
  "OrderId" : 1,
  "CustomerName" : "john" 
}

you would get serialization errors if queue data cannot be serialized to the expected GenericType. For e.g following function would fail trying to process the bad queue input: function:

public static void ProcessQueueMessage([QueueTrigger("queuea")] GenericInput<int> message, TextWriter log)
    {
        log.WriteLine(message);
    }

bad input:

{
 "OrderId" : 1,
 "CustomerName" : "cannot covert string to number" 
}
Cathiecathleen answered 20/3, 2018 at 18:42 Comment(8)
When debugging locally, you should see errors on the console. When deployed to azure, application insights would have details logs. Serializing queue data happens before executing the function code. So, you will not be able to hit a breakpoint inside the function code. Can you update the question with the code for BackOfficeFileGeneratorMessage?Cathiecathleen
I’m debugging it locally, I cannot see my error on console.Byre
No way to debug for queue data?Byre
Is there any way to see or change this preprocessing method?Byre
Updated question, sorry for bad formatting, I typed it from phone, please check.Byre
Here is some information on supported queue messages:how-to-trigger-a-function-when-a-queue-message-is-received. Queue trigger binding does not have support for a complex type like the one you are using. It is strange that you do not see any errors. If you still would like to debug- here is the queueporcessor code. You need to debug webjobs sdk.Cathiecathleen
If you could provide a simple repro, I can help investigate further.Cathiecathleen
You can simply reproduce the case by using generics in messages like I have used in my code.Byre
C
3

just add the next key:value to the hosts.json:

"singleton": {
    "listenerLockPeriod": "00:00:15" 
  }
Crandall answered 23/1, 2019 at 9:12 Comment(0)
C
2

Functions runtime acquires lease on the storage account attached to the function app using an unique Id that is specific to your function App. This is an internal implementation detail.

Deserializing to a generic type should work as long as the queue trigger data matches the POCO. For e.g, here is generic type

public class GenericInput<T>
{
    public T OrderId { get; set; }

    public T CustomerName { get; set; }
}

and the function

 public static void ProcessQueueMessage([QueueTrigger("queuea")] GenericInput<string> message, TextWriter log)
    {
        log.WriteLine(message);
    }

Sample queue data

{
  "OrderId" : 1,
  "CustomerName" : "john" 
}

you would get serialization errors if queue data cannot be serialized to the expected GenericType. For e.g following function would fail trying to process the bad queue input: function:

public static void ProcessQueueMessage([QueueTrigger("queuea")] GenericInput<int> message, TextWriter log)
    {
        log.WriteLine(message);
    }

bad input:

{
 "OrderId" : 1,
 "CustomerName" : "cannot covert string to number" 
}
Cathiecathleen answered 20/3, 2018 at 18:42 Comment(8)
When debugging locally, you should see errors on the console. When deployed to azure, application insights would have details logs. Serializing queue data happens before executing the function code. So, you will not be able to hit a breakpoint inside the function code. Can you update the question with the code for BackOfficeFileGeneratorMessage?Cathiecathleen
I’m debugging it locally, I cannot see my error on console.Byre
No way to debug for queue data?Byre
Is there any way to see or change this preprocessing method?Byre
Updated question, sorry for bad formatting, I typed it from phone, please check.Byre
Here is some information on supported queue messages:how-to-trigger-a-function-when-a-queue-message-is-received. Queue trigger binding does not have support for a complex type like the one you are using. It is strange that you do not see any errors. If you still would like to debug- here is the queueporcessor code. You need to debug webjobs sdk.Cathiecathleen
If you could provide a simple repro, I can help investigate further.Cathiecathleen
You can simply reproduce the case by using generics in messages like I have used in my code.Byre
P
1

If this happens on localhost you can try to clear Azurite emulator (Visual Studio 2022) or Azure Storage Emulator

Azurite emulator:

Goto

%temp%\Azurite

Clear everything so you only have these two empty folders left:

enter image description here

https://mcmap.net/q/378901/-how-to-clear-azure-storage-emulator-data-from-command-line

https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite?toc=%2Fazure%2Fstorage%2Fblobs%2Ftoc.json&tabs=visual-studio

Azure Storage Emulator:

cd C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator
.\AzureStorageEmulator.exe clear all

https://mcmap.net/q/378901/-how-to-clear-azure-storage-emulator-data-from-command-line

https://learn.microsoft.com/en-us/azure/storage/common/storage-use-emulator

Psychosomatics answered 27/10, 2022 at 15:30 Comment(0)
M
0

If you upload a file on blob and run a trigger against it, the file will be read one time only. If you need to run the function again for the same file it is not possible. You can either remove the file from blob and put it there again using UI (which will serve as a new trigger) or change the path of your function on your machine and keep the file on the blob as it is.

Mho answered 10/4, 2020 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.