Skip to content

Commit

Permalink
feat(core): Display more worker info on bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Jun 18, 2019
1 parent 5795b26 commit edbcbc4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
17 changes: 15 additions & 2 deletions packages/core/src/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { INestApplication, INestMicroservice } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { Transport } from '@nestjs/microservices';
import { TcpClientOptions, Transport } from '@nestjs/microservices';
import { Type } from '@vendure/common/lib/shared-types';
import { worker } from 'cluster';
import { EntitySubscriberInterface } from 'typeorm';

import { InternalServerError } from './common/error/errors';
Expand Down Expand Up @@ -78,6 +77,7 @@ async function bootstrapWorkerInternal(userConfig: Partial<VendureConfig>): Prom
DefaultLogger.restoreOriginalLogLevel();
workerApp.useLogger(new Logger());
await workerApp.listenAsync();
workerWelcomeMessage(config);
return workerApp;
}

Expand Down Expand Up @@ -179,6 +179,19 @@ function getEntitiesFromPlugins(userConfig: Partial<VendureConfig>): Array<Type<
.reduce((all, entities) => [...all, ...entities], []);
}

function workerWelcomeMessage(config: VendureConfig) {
let transportString = '';
let connectionString = '';
const transport = (config.workerOptions && config.workerOptions.transport) || Transport.TCP;
transportString = ` with ${Transport[transport]} transport`;
const options = (config.workerOptions as TcpClientOptions).options;
if (options) {
const { host, port } = options;
connectionString = ` at ${host || 'localhost'}:${port}`;
}
Logger.info(`Vendure Worker started${transportString}${connectionString}`);
}

function logWelcomeMessage(config: VendureConfig) {
let version: string;
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/config/default-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const defaultConfig: ReadOnlyRequired<VendureConfig> = {
runInMainProcess: false,
transport: Transport.TCP,
options: {
port: 3001,
port: 3020,
},
},
customFields: {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/config/vendure-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ export interface WorkerOptions {
* Additional options related to the chosen transport method. See See the
* [NestJS microservices documentation](https://docs.nestjs.com/microservices/basics) for details on the options relating to each of the
* transport methods.
*
* By default, the options for the TCP transport will run with the following settings:
* * host: 'localhost'
* * port: 3020
*/
options?: ClientOptions['options'];
}
Expand Down

0 comments on commit edbcbc4

Please sign in to comment.