0

Summary ToDo : I am trying to run r-script in docker which is having some calculation logic interacting to database. This script run for around one hour.

What I have tried : I have tried to use azure durable function which triggers r-script in docker and here is the example to do so:

[FunctionName(nameof(RunRScript))]
    public static async Task<string> RunRScript([ActivityTrigger] string name, ILogger log)
    {
        log.LogInformation($"Starting R script execution...");

        // Command to run the R script in the Docker container
        var process = new Process
        {
            StartInfo = new ProcessStartInfo
            {
                FileName = "docker", 
                Arguments = "run -p 80:80 testing.azurecr.io/test_docker:latest",
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                UseShellExecute = false,
                CreateNoWindow = true
            }
            
        };

        process.Start();

        string output = await process.StandardOutput.ReadToEndAsync();
        string error = await process.StandardError.ReadToEndAsync();

        process.WaitForExit();

        if (process.ExitCode != 0)
        {
            log.LogError($"R script execution failed: {error}");
            throw new Exception($"R script execution failed: {error}");
        }

        log.LogInformation($"R script execution completed successfully: {output}");
        return output;
    }

    [FunctionName("Function1_HttpStart")]
    public static async Task<HttpResponseMessage> HttpStart(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestMessage req,
        [DurableClient] IDurableOrchestrationClient starter,
        ILogger log)
    {
        // Function input comes from the request content.
        string instanceId = await starter.StartNewAsync("Function1", null);

        log.LogInformation("Started orchestration with ID = '{instanceId}'.", instanceId);

        return starter.CreateCheckStatusResponse(req, instanceId);
    }

Problem: So problem here is that I am able to run FunctionApp in my development machine however it failing to run once deployed to azure function app.

Limitations: I am not allowed to use VMs due to cost issues

1 Answer 1

0

So I have solution for above problem:

Since I was using http request with r_script to call Api's and docker was running for longer time to perform certain database calculations, I ended up with the time out after 240 second due to limitations of http request.

Solution: So my simple solution was to make r_script request API asynchronous so that my API's will respond immediately with response and docker will keep running in background to perform its action.

Status: There are 2 ways to check status of the request. First is to use database logs as we are performing calculation logic in database and second is to create another api to check the status of the API.

Note: We have similar things available in durable functions which responds immediately, however it also returns url to check the status of the call

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.