Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down
32 changes: 10 additions & 22 deletions workers/grouper/src/redisHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,11 @@ export default class RedisHelper {
): Promise<void> {
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);
}

/**
Expand Down Expand Up @@ -252,17 +246,11 @@ export default class RedisHelper {
): Promise<void> {
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);
}

/**
Expand Down
Loading