Просмотр исходного кода

feat(core): Display more worker info on bootstrap

Michael Bromley 6 лет назад
Родитель
Сommit
edbcbc48e7

+ 15 - 2
packages/core/src/bootstrap.ts

@@ -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';
@@ -78,6 +77,7 @@ async function bootstrapWorkerInternal(userConfig: Partial<VendureConfig>): Prom
     DefaultLogger.restoreOriginalLogLevel();
     workerApp.useLogger(new Logger());
     await workerApp.listenAsync();
+    workerWelcomeMessage(config);
     return workerApp;
 }
 
@@ -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 {

+ 1 - 1
packages/core/src/config/default-config.ts

@@ -84,7 +84,7 @@ export const defaultConfig: ReadOnlyRequired<VendureConfig> = {
         runInMainProcess: false,
         transport: Transport.TCP,
         options: {
-            port: 3001,
+            port: 3020,
         },
     },
     customFields: {

+ 4 - 0
packages/core/src/config/vendure-config.ts

@@ -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'];
 }