Delayed execution of external tasks

Hello all,

I am using Camunda.Worker in my .NET application to create some topic handlers that will complete the service tasks in my Camunda process. Recently (not always) it takes a long time to handle these tasks. I see the logs of my backend and I see it sends requests (fetchAndLock) for some time before it actually executes it. It may take like 5 minutes which is obviously not viable. I don’t know if I need further configuration of my handlers. If anyone can provide some additional information I would appreciate it.

{“version”:“7.19.0”}

Following, I am adding an example of my handler.

Thank you in advance!

[HandlerTopics(“CreateOrder”)]

public class CreateOrderHandler : IExternalTaskHandler
{

public CreateOrderHandler(ILogger<CreateOrderHandler> logger, IFileManager file,
    ICamundaProvider camundaProvider,
    IOrderSubmissionService orderSubmissionService)
{
    _logger = logger;
    _file = file;
    _orderSubmissionService = orderSubmissionService;
    _camundaProvider = camundaProvider;
            }

public async Task<IExecutionResult> HandleAsync(ExternalTask externalTask, CancellationToken cancellationToken)
{
    try
    {
        string businessKey = externalTask.BusinessKey;

        OrderSubmission orderSubmission = await _orderSubmissionService
            .GetCOrderSubmissionByBusinessKey(businessKey, cancellationToken);

        if (orderSubmission == null)
        {
            return null;
        }

        _logger.LogWarning($"businessKey: {businessKey}");

        GeneralResponse<FileDto> response = await _file.GeneratePdf(businessKey, "created_order", cancellationToken);

        var updateResult = await _orderSubmissionService.UpdateOrderSubmissionTaskName(orderSubmission, "Ανάθεση");

        return await _camundaProvider.CreateOrderProtocol(response.Result.FileName);

    }
    catch (Exception ex)
    {
        _logger.LogError($"error occurred!! error message: {ex.Message}");

        return new BpmnErrorResult("CreateOrderFailure", "Error occurred while creatingorder.");
    }
}

}

This is very likely due to the settings of the Job Executor in the engine. Specifically the job acquisition settings

For details i suggest you take a look at this great blog post on the topic, that should help you understand what might be going on.

1 Like

Thank you @Niall for your answer. However does it make sense that I keep observing this behaviour lately after many months of testing?

Depends on how you’ve tested it.
External tasks are more likely to trigger faster if you’ve added long polling to them, otherwise its possible that if they find no work to do after x number of requests they request work less often. So during a period where not much is happening it it’ll take longer to pick things back up.

1 Like

Ok I understand. I am wondering because there were no changes in my Handler, but I will look better the job acquisition settings.

Finally, by checking my backend service logs I see that the fetchAndLock request is happening every a certain amount of time but it fails to find(?) a task although there are active ones in my flow.

Thanks again!