diff --git a/runner.ts b/runner.ts index 443beea8..5dd05b1b 100644 --- a/runner.ts +++ b/runner.ts @@ -12,10 +12,6 @@ import * as dotenv from 'dotenv'; dotenv.config(); -if (process.env.HAWK_CATCHER_TOKEN) { - HawkCatcher.init(process.env.HAWK_CATCHER_TOKEN); -} - type WorkerConstructor = new () => Worker; const BEGINNING_OF_ARGS = 2; @@ -27,6 +23,18 @@ const BEGINNING_OF_ARGS = 2; */ const workerNames = process.argv.slice(BEGINNING_OF_ARGS); +/** + * Initialize HawkCatcher +*/ +if (process.env.HAWK_CATCHER_TOKEN) { + HawkCatcher.init({ + token: process.env.HAWK_CATCHER_TOKEN, + context: { + workerTypes: workerNames.join(","), + } + }); +} + /** * Workers dispatcher. * Load, run and finish workers. diff --git a/workers/grouper/src/redisHelper.ts b/workers/grouper/src/redisHelper.ts index ec486ddb..57a35543 100644 --- a/workers/grouper/src/redisHelper.ts +++ b/workers/grouper/src/redisHelper.ts @@ -193,17 +193,11 @@ export default class RedisHelper { ): Promise { const timestamp = Date.now(); - try { - await this.tsIncrBy(key, value, timestamp, labels); - } catch (error) { - if (error instanceof Error && error.message.includes('TSDB: key does not exist')) { - this.logger.warn(`TS key ${key} does not exist, creating it...`); - await this.tsCreateIfNotExists(key, labels, retentionMs); - await this.tsIncrBy(key, value, timestamp, labels); - } else { - throw error; - } - } + /** + * Create key if not exists — then call increment + */ + await this.tsCreateIfNotExists(key, labels, retentionMs); + await this.tsIncrBy(key, value, timestamp, labels); } /** @@ -252,17 +246,11 @@ export default class RedisHelper { ): Promise { const timestamp = Date.now(); - try { - await this.tsAdd(key, value, timestamp, labels); - } catch (error) { - if (error instanceof Error && error.message.includes('TSDB: key does not exist')) { - this.logger.warn(`TS key ${key} does not exist, creating it...`); - await this.tsCreateIfNotExists(key, labels, retentionMs); - await this.tsAdd(key, value, timestamp, labels); - } else { - throw error; - } - } + /** + * Create key if not exists — then call increment + */ + await this.tsCreateIfNotExists(key, labels, retentionMs); + await this.tsAdd(key, value, timestamp, labels); } /**