|
| 1 | +// ↓ Should be imported first |
| 2 | +const { terminate } = require('@codefresh-io/cf-telemetry/init'); |
| 3 | +// ↓ Keep one blank line below to prevent automatic import reordering |
| 4 | + |
1 | 5 | const fs = require('fs');
|
2 | 6 | const { EventEmitter } = require('events');
|
3 | 7 | const _ = require('lodash');
|
@@ -64,12 +68,12 @@ class Logger {
|
64 | 68 | * validates the passed params of the constructor
|
65 | 69 | * @returns {*}
|
66 | 70 | */
|
67 |
| - validate() { |
| 71 | + async validate() { |
68 | 72 | if (!this.taskLoggerConfig) {
|
69 |
| - return this._error(new CFError('taskLogger configuration is missing')); |
| 73 | + return await this._error(new CFError('taskLogger configuration is missing')); |
70 | 74 | }
|
71 | 75 | if (!this.loggerId) {
|
72 |
| - return this._error(new CFError('logger id is missing')); |
| 76 | + return await this._error(new CFError('logger id is missing')); |
73 | 77 | }
|
74 | 78 | return undefined;
|
75 | 79 | }
|
@@ -120,8 +124,8 @@ class Logger {
|
120 | 124 | this._listenForExistingContainers();
|
121 | 125 | }
|
122 | 126 | })
|
123 |
| - .catch((err) => { |
124 |
| - this._error(new CFError({ |
| 127 | + .catch(async (err) => { |
| 128 | + await this._error(new CFError({ |
125 | 129 | cause: err,
|
126 | 130 | message: `Failed to create taskLogger`
|
127 | 131 | }));
|
@@ -149,8 +153,9 @@ class Logger {
|
149 | 153 | * will print the error and exit the process
|
150 | 154 | * @param err
|
151 | 155 | */
|
152 |
| - _error(err) { |
| 156 | + async _error(err) { |
153 | 157 | logger.error(err.toString());
|
| 158 | + await terminate(); |
154 | 159 | process.exit(1);
|
155 | 160 | }
|
156 | 161 |
|
@@ -344,9 +349,9 @@ class Logger {
|
344 | 349 | */
|
345 | 350 | _listenForExistingContainers() {
|
346 | 351 | logger.info(`Finding existing containers to listen on`);
|
347 |
| - this.docker.listContainers((err, containers) => { |
| 352 | + this.docker.listContainers(async (err, containers) => { |
348 | 353 | if (err) {
|
349 |
| - this._error(new CFError({ |
| 354 | + await this._error(new CFError({ |
350 | 355 | cause: err,
|
351 | 356 | message: `Query of existing containers failed`
|
352 | 357 | }));
|
|
0 commit comments