I’m very new with durable functions V4 in javascript but I cannot get this activity to run properly. I always get an error as apparently I’m not passing in the Instance ID correctly.
What am I doing wrong here? The tutorial page on the microsoft website was of no use.
Here is the code:
df.app.orchestration('reportOrchestrator', function* (context) {
try {
const instanceId = context.df.instanceId; // Get the current orchestration's instance ID
context.log(`Orchestration instance ID: ${instanceId}`);
const lsFile = { instanceID: instanceId }; // Pass instanceID in an object
const token = yield context.df.callActivity('TokenManager', { instanceID: instanceId });
context.log(`Token retrieved: ${token}`);
return token;
// const result = yield context.df.callActivity('PipelineQuery', { token });
} catch (error) {
return error.message;
context.log(`Error in orchestration: ${error.message}`);
throw error;
}
});
df.app.activity('TokenManager', {
handler: async (context) => {
const log = context.log;
const lsFile = context.getClient().instanceID; // Direct input passed from the orchestrator
if (!lsFile || !lsFile.instanceID) {
//log("InstanceID is missing or undefined");
throw new Error("InstanceID is missing or undefined,", context);
}
const instanceID = lsFile;
//log(`Orchestrator Instance ID is ${instanceID}`);
let functionID = "POST Reports Orchestrator";
try {
// Make the POST request to retrieve the token
const tokenResponse = await axios.post(logicAppURL, {
requestType: "GET_TOKEN",
functionID: functionID,
});
// Check if token was successfully retrieved
if (tokenResponse.data && tokenResponse.data.token) {
//log("Token successfully retrieved");
return tokenResponse.data.token;
} else {
//log("Token could not be retrieved. Functions will generate their own token");
await mandrillGeneralError(log, "Error retrieving token on POST Reports Orchestrator Token Manager function app in Azure.");
return ""; // Return empty token if retrieval fails
}
} catch (error) {
//log(`Error retrieving token: ${error.message}`);
await mandrillGeneralError(log, `Error retrieving token: ${error.message}`);
throw error; // Throw the error so it's logged properly by Durable Functions
}
}
});