Skip to content

Commit

Permalink
Add script file properties to function metadata (#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejizba committed Nov 14, 2022
1 parent a090cc0 commit 7f2afaa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/WorkerChannel.ts
Expand Up @@ -50,6 +50,7 @@ export class WorkerChannel {
functions: { [id: string]: RegisteredFunction } = {};
workerIndexingLocked = false;
isUsingWorkerIndexing = false;
currentEntryPoint?: string;

constructor(workerId: string, eventStream: IEventStream, legacyFunctionLoader: ILegacyFunctionLoader) {
this.workerId = workerId;
Expand Down
14 changes: 11 additions & 3 deletions src/coreApi/registerFunction.ts
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

import { FunctionCallback, FunctionMetadata } from '@azure/functions-core';
import * as path from 'path';
import { AzureFunctionsRpcMessages as rpc } from '../../azure-functions-language-worker-protobuf/src/rpc';
import { Disposable } from '../Disposable';
import { AzFuncSystemError } from '../errors';
Expand All @@ -27,9 +28,16 @@ export function registerFunction(
rpcMetadata.rawBindings = Object.entries(metadata.bindings).map(([name, binding]) => {
return JSON.stringify({ ...binding, name });
});
// The host validates that the `scriptFile` property is defined even though neither the host nor the worker needs it
// Long term we should adjust the host to remove that unnecessary validation, but for now we'll just set it to 'n/a'
rpcMetadata.scriptFile = 'n/a';

// The host validates that the `scriptFile` property is defined. Neither the host nor the worker needs it, but tooling like the portal may use it so we'll make a best guess
// (The real script file may be a separate file referenced from the entry point, or it may be coming from a different entry point entirely if there are some async shenanigans)
if (channel.currentEntryPoint) {
rpcMetadata.scriptFile = path.basename(channel.currentEntryPoint);
rpcMetadata.directory = path.dirname(channel.currentEntryPoint);
} else {
rpcMetadata.scriptFile = 'unknown';
}

channel.functions[functionId] = { metadata: rpcMetadata, callback };

return new Disposable(() => {
Expand Down
8 changes: 7 additions & 1 deletion src/startApp.ts
Expand Up @@ -55,7 +55,13 @@ async function loadEntryPointFile(functionAppDirectory: string, channel: WorkerC
level: LogLevel.Debug,
logCategory: LogCategory.System,
});
await loadScriptFile(path.join(functionAppDirectory, file), channel.packageJson);
try {
const entryPointFilePath = path.join(functionAppDirectory, file);
channel.currentEntryPoint = entryPointFilePath;
await loadScriptFile(entryPointFilePath, channel.packageJson);
} finally {
channel.currentEntryPoint = undefined;
}
channel.log({
message: `Loaded entry point file "${file}"`,
level: LogLevel.Debug,
Expand Down

0 comments on commit 7f2afaa

Please sign in to comment.