Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(console): hide simulator updates feature behind WING_ENABLE_INPLACE_UPDATES #6144

Merged
merged 4 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions apps/wing-console/console/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export type RouteNames = keyof inferRouterInputs<Router> | undefined;

export { isTermsAccepted } from "./utils/terms-and-conditions.js";

const enableSimUpdates =
process.env.WING_ENABLE_INPLACE_UPDATES === "true" ||
process.env.WING_ENABLE_INPLACE_UPDATES === "1";

export interface CreateConsoleServerOptions {
wingfile: string;
log: LogInterface;
Expand Down Expand Up @@ -134,7 +138,10 @@ export const createConsoleServer = async ({
let isStarting = false;
let isStopping = false;

const simulator = createSimulator({ stateDir });
const simulator = createSimulator({
stateDir,
enableSimUpdates,
});
if (onTrace) {
simulator.on("trace", onTrace);
}
Expand All @@ -150,7 +157,7 @@ export const createConsoleServer = async ({
platform,
testing: true,
});
const testSimulator = createSimulator();
const testSimulator = createSimulator({ enableSimUpdates });
testCompiler.on("compiled", ({ simfile }) => {
testSimulator.start(simfile);
});
Expand Down
24 changes: 18 additions & 6 deletions apps/wing-console/console/server/src/utils/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface Simulator {

export interface CreateSimulatorProps {
stateDir?: string;
enableSimUpdates?: boolean;
}

const stopSilently = async (simulator: simulator.Simulator) => {
Expand All @@ -45,13 +46,25 @@ const stopSilently = async (simulator: simulator.Simulator) => {
export const createSimulator = (props?: CreateSimulatorProps): Simulator => {
const events = new Emittery<SimulatorEvents>();
let instance: simulator.Simulator | undefined;
const handleExistingInstance = async (simfile: string): Promise<boolean> => {
if (!instance) {
return true;
}
if (props?.enableSimUpdates) {
await events.emit("starting", { instance });
await instance.update(simfile);
await events.emit("started");
return false;
} else {
await events.emit("stopping");
await stopSilently(instance);
return true;
}
};
const start = async (simfile: string) => {
try {
if (instance) {
await events.emit("starting", { instance });
await instance.update(simfile);
await events.emit("started");
} else {
const shouldStartSim = await handleExistingInstance(simfile);
if (shouldStartSim) {
instance = new simulator.Simulator({
simfile,
stateDir: props?.stateDir,
Expand All @@ -61,7 +74,6 @@ export const createSimulator = (props?: CreateSimulatorProps): Simulator => {
events.emit("trace", trace);
},
});

await events.emit("starting", { instance });
await instance.start();
await events.emit("started");
Expand Down
Loading