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