Skip to content

Commit

Permalink
Refactor floating string.
Browse files Browse the repository at this point in the history
  • Loading branch information
taeold committed Jan 31, 2023
1 parent cec9d2c commit 7a3e720
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/emulator/functionsRuntimeWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export enum RuntimeWorkerState {
FINISHED = "FINISHED",
}

/**
* Given no trigger key, worker is given this special key.
*
* This is useful when running the Functions Emulator in debug mode
* where single process shared amongst all triggers.
*/
const FREE_WORKER_KEY = "~free~";

export class RuntimeWorker {
readonly id: string;
readonly triggerKey: string;
Expand All @@ -46,7 +54,7 @@ export class RuntimeWorker {
readonly timeoutSeconds?: number
) {
this.id = uuid.v4();
this.triggerKey = triggerId || "~free~";
this.triggerKey = triggerId || FREE_WORKER_KEY;
this.runtime = runtime;

const childProc = this.runtime.process;
Expand Down Expand Up @@ -118,14 +126,14 @@ export class RuntimeWorker {
}

request(req: http.RequestOptions, resp: http.ServerResponse, body?: unknown): Promise<void> {
if (this.triggerKey !== "~free~") {
if (this.triggerKey !== FREE_WORKER_KEY) {
this.logInfo(`Beginning execution of "${this.triggerKey}"`);
}
const startHrTime = process.hrtime();

this.state = RuntimeWorkerState.BUSY;
const onFinish = (): void => {
if (this.triggerKey !== "~free~") {
if (this.triggerKey !== FREE_WORKER_KEY) {
const elapsedHrTime = process.hrtime(startHrTime);
this.logInfo(
`Finished "${this.triggerKey}" in ${
Expand Down

0 comments on commit 7a3e720

Please sign in to comment.