Skip to content

Commit

Permalink
feat(core): Prevent calling bootstrapWorker when runInMainProcess = true
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Jun 18, 2019
1 parent 9b3cd26 commit dc8e173
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/core/src/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,29 @@ export async function bootstrap(userConfig: Partial<VendureConfig>): Promise<INe
await runPluginOnBootstrapMethods(config, app);
await app.listen(config.port, config.hostname);
if (config.workerOptions.runInMainProcess) {
await bootstrapWorker(config);
await bootstrapWorkerInternal(config);
Logger.warn(`Worker is running in main process. This is not recommended for production.`);
Logger.warn(`[VendureConfig.workerOptions.runInMainProcess = true]`);
}
logWelcomeMessage(config);
return app;
}

/**
* Bootstrap the Vendure worker.
*/
export async function bootstrapWorker(userConfig: Partial<VendureConfig>): Promise<INestMicroservice> {
if (userConfig.workerOptions && userConfig.workerOptions.runInMainProcess === true) {
Logger.useLogger(userConfig.logger || new DefaultLogger());
const errorMessage = `Cannot bootstrap worker when "runInMainProcess" is set to true`
Logger.error(errorMessage, 'Vendure Worker');
throw new Error(errorMessage);
} else {
return bootstrapWorkerInternal(userConfig);
}
}

async function bootstrapWorkerInternal(userConfig: Partial<VendureConfig>): Promise<INestMicroservice> {
const config = await preBootstrapConfig(userConfig);
if (!config.workerOptions.runInMainProcess && (config.logger as any).setDefaultContext) {
(config.logger as any).setDefaultContext('Vendure Worker');
Expand Down

0 comments on commit dc8e173

Please sign in to comment.