-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
75 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { AppManager } from '../AppManager'; | ||
import type { IParseAppPackageResult } from '../compiler'; | ||
import { DenoRuntimeSubprocessController } from '../runtime/AppsEngineDenoRuntime'; | ||
|
||
export type AppRuntimeParams = { | ||
appId: string; | ||
appSource: string; | ||
}; | ||
|
||
export type ExecRequestContext = { | ||
method: string; | ||
params: unknown[]; | ||
}; | ||
|
||
export type ExecRequestOptions = { | ||
timeout?: number; | ||
}; | ||
|
||
export class AppRuntimeManager { | ||
private readonly subprocesses: Record<string, DenoRuntimeSubprocessController> = {}; | ||
|
||
constructor(private readonly manager: AppManager) {} | ||
|
||
public async startRuntimeForApp(appPackage: IParseAppPackageResult, options = { force: false }): Promise<DenoRuntimeSubprocessController> { | ||
const { id: appId } = appPackage.info; | ||
|
||
if (appId in this.subprocesses && !options.force) { | ||
throw new Error('App already has an associated runtime'); | ||
} | ||
|
||
this.subprocesses[appId] = new DenoRuntimeSubprocessController(this.manager, appPackage); | ||
|
||
await this.subprocesses[appId].setupApp(); | ||
|
||
return this.subprocesses[appId]; | ||
} | ||
|
||
public async runInSandbox(appId: string, execRequest: ExecRequestContext, options?: ExecRequestOptions): Promise<unknown> { | ||
const subprocess = this.subprocesses[appId]; | ||
|
||
if (!subprocess) { | ||
throw new Error('App does not have an associated runtime'); | ||
} | ||
|
||
return subprocess.sendRequest(execRequest); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters