in src/eventHandlers/FunctionEnvironmentReloadHandler.ts [30:85]
async handleEvent(msg: rpc.IFunctionEnvironmentReloadRequest): Promise<rpc.IFunctionEnvironmentReloadResponse> {
if (!msg.functionAppDirectory) {
worker.log({
message: `FunctionEnvironmentReload functionAppDirectory is not defined`,
level: LogLevel.Debug,
logCategory: LogCategory.System,
});
}
if (
worker.app.functionAppDirectory &&
msg.functionAppDirectory &&
isPathEqual(worker.app.functionAppDirectory, msg.functionAppDirectory)
) {
worker.log({
message: `FunctionEnvironmentReload functionAppDirectory has not changed`,
level: LogLevel.Debug,
logCategory: LogCategory.System,
});
}
worker.resetApp(msg.functionAppDirectory);
const response = this.getDefaultResponse(msg);
// Add environment variables from incoming
const numVariables = (msg.environmentVariables && Object.keys(msg.environmentVariables).length) || 0;
worker.log({
message: `Reloading environment variables. Found ${numVariables} variables to reload.`,
level: LogLevel.Information,
logCategory: LogCategory.System,
});
// reset existing env vars
Object.keys(process.env).map((key) => delete process.env[key]);
// set new env vars
Object.assign(process.env, msg.environmentVariables);
// Change current working directory
if (msg.functionAppDirectory) {
worker.log({
message: `Changing current working directory to ${msg.functionAppDirectory}`,
level: LogLevel.Information,
logCategory: LogCategory.System,
});
process.chdir(msg.functionAppDirectory);
await startApp(msg.functionAppDirectory);
// model info may have changed, so we need to update this
response.workerMetadata = getWorkerMetadata();
}
response.capabilities = await getWorkerCapabilities();
response.capabilitiesUpdateStrategy = CapabilitiesUpdateStrategy.replace;
return response;
}