3

I have an Azure durable function triggered by a message that then uses the client to start an Orchestration trigger which starts several activity functions. I have set breakpoints in Orchestration client , trigger and each activity function. But, it only hits the breakpoints in Orchestration client function and the others are getting ignored. But underneath it seems to execute the activity functions although the breakpoints are not hit.

Investigative information

  • Programming language used = C#
  • Visual Studio Enterprise 2019 version = 16.8.3
  • Azure Functions Core Tools Core Tools Version: 3.0.3216 Function Runtime Version: 3.0.15193.0

Below here, I have included a code snippet. (have not added every activity function)

[FunctionName(nameof(InitiateExport))]
        public static async Task InitiateExport(
            [ServiceBusTrigger("%ExportQueueName%", Connection = "AzureSBConnection")]Message message,
            [DurableClient(TaskHub = "%FunctionHubName%")] IDurableOrchestrationClient orchestrationClient,
            [Inject]IServiceProvider rootServiceProvider, ILogger log)
        {
            var DataQueuedDetails = JsonConvert.DeserializeObject<DataQueuedDetails>(Encoding.UTF8.GetString(message.Body));

            using (var scope = rootServiceProvider.CreateScope())
            {
                log.LogInformation($"{nameof(ExportData)} function execution started at: {DateTime.Now}");
                
                var services = scope.ServiceProvider;
                services.ResolveRequestContext(message);
                var requestContext = services.GetRequiredService<RequestContext>();

                await orchestrationClient.StartNewAsync(nameof(TriggerDataExport), null, (DataQueuedDetails, requestContext));

                log.LogInformation($"{nameof(ExportData)} timer triggered function execution finished at: {DateTime.Now}");
            }
        }    

[FunctionName(nameof(TriggerDataExport))]
        public static async Task TriggerDataExport(
            [OrchestrationTrigger] IDurableOrchestrationContext orchestrationContext,
            [Inject] IServiceProvider rootServiceProvider, ILogger log)
        {

     using (var scope = rootServiceProvider.CreateScope())
            {               

                var services = scope.ServiceProvider;
                var (DataOperationInfo, requestContext) = orchestrationContext.GetInput<(DataQueuedDetails, RequestContext)>();
                
                if (!orchestrationContext.IsReplaying)
                    log.LogInformation($"Starting Export data Id {DataOperationInfo.Id}");
                
                var blobServiceFactory = services.GetRequiredService<IBlobServiceFactory>();
                requestContext.CustomerId = DataOperationInfo.RelatedCustomerId;
                
                try
                 {                       
                        await orchestrationContext.CallActivityAsync(
                             nameof(UpdateJobStatus),
                             (DataOperationInfo.Id, DataOperationStatus.Running, string.Empty, string.Empty, requestContext));
                    
                     // some other activity functions
                  ---
                  ---
                } catch (Exception e)
                {                   
                    await orchestrationContext.CallActivityAsync(
                        nameof(UpdateJobStatus),
                        (DataOperationInfo.Id, DataOperationStatus.Failed, string.Empty, string.Empty, requestContext));
                    
                }
          }
}

[FunctionName(nameof(UpdateJobStatus))]
        public static async Task RunAsync(
            [ActivityTrigger] IDurableActivityContext activityContext,
            [Inject]IServiceProvider rootServiceProvider)
        {
            using (var scope = rootServiceProvider.CreateScope())
            {
                try
                {
                    var (DataOperationId, status, blobReference, logFileBlobId, requestContext) = activityContext.GetInput<(string, string, string, string, RequestContext)>();
                    var services = scope.ServiceProvider;
                    services.ResolveRequestContext(requestContext.CustomerId, requestContext.UserId, requestContext.UserDisplayName, requestContext.Culture);
                    var dataService = services.GetRequiredService<IDataService>();
                    var DataOperationDto = new DataOperationDto
                    {
                        Id = DataOperationId,
                        OperationStatusCode = status,
                        BlobReference = blobReference,
                        LogBlobReference = logFileBlobId
                    };
                    await dataService.UpdateAsync(DataOperationDto);
                }
                catch (Exception e)
                {
                    throw e;
                }
                
            }
        }
                
HirSK
  • 63
  • 6
  • how about you start by sharing some relevant source code? How else should anybody help you? – silent Jan 08 '21 at 13:03
  • @silent, I updated my post with the code – HirSK Jan 08 '21 at 13:21
  • 1
    While you are debugging your Function, are you using a local storage emulator? Or an actual Storage Account that might also be used by the Function already deployed in Azure? then it could be, that parts of the execution is actually happening in Azure instead of your dev machine – silent Jan 08 '21 at 13:49
  • @silent yes I'm using the actual storage. Do you mean that I need to disable the Function deployed in Azure? Thank you very much for responding. I'll take a look on that – HirSK Jan 08 '21 at 14:48
  • Yes, either that or, what I would rather recommend, use a different storage account for dev/debugging – silent Jan 08 '21 at 14:50
  • @silent I disabled the function in Azure, but still the issue remains. And by the way, it takes a long time (around 10 mins) to hit my local durable client function. The message get stuck a very long time in the service bus queue. Is this has a relationship with this issue? – HirSK Jan 08 '21 at 15:09
  • hm no idea, but sounds like something is wrong with your local debugging env – silent Jan 08 '21 at 15:16
  • @silent I disabled only the client function. My mistake. Then I disabled all the client , trigger and activity functions, then it worked fine. You saved days. Thank you so much – HirSK Jan 08 '21 at 15:21
  • ahh, glad to hear it :) I'll make an answer out of that so other people can find it as well – silent Jan 08 '21 at 15:22

1 Answers1

3

While you are debugging your Function, you should make sure that you are either using the local storage emulator, or an Azure Storage Account that is different from the one that is also being used by the Function already deployed in Azure.

If you are using the same storage account that another running Function is using, then it could be that parts of the execution is actually happening in Azure instead of your dev machine.

silent
  • 14,494
  • 4
  • 46
  • 86