Skip to content

Commit

Permalink
[OTE-880] Emit log in case of collisions (#2500)
Browse files Browse the repository at this point in the history
  • Loading branch information
affanv14 authored Oct 16, 2024
1 parent 78b2f93 commit a18eb61
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { logger } from '@dydxprotocol-indexer/base';
import { logger, stats } from '@dydxprotocol-indexer/base';
import {
SubaccountUsernamesTable,
SubaccountsWithoutUsernamesResult,
} from '@dydxprotocol-indexer/postgres';

import config from '../config';
import { generateUsername } from '../helpers/usernames-helper';

export default async function runTask(): Promise<void> {
Expand All @@ -21,13 +22,18 @@ export default async function runTask(): Promise<void> {
subaccountId: subaccount.subaccountId,
});
} catch (e) {
logger.error({
at: 'subaccount-username-generator#runTask',
message: 'Failed to insert username for subaccount',
subaccountId: subaccount.subaccountId,
username,
error: e,
});
if (e instanceof Error && e.name === 'UniqueViolationError') {
stats.increment(
`${config.SERVICE_NAME}.subaccount-username-generator.collision`, 1);
} else {
logger.error({
at: 'subaccount-username-generator#runTask',
message: 'Failed to insert username for subaccount',
subaccountId: subaccount.subaccountId,
username,
error: e,
});
}
}
}
}

0 comments on commit a18eb61

Please sign in to comment.