Skip to content

Commit

Permalink
add log for run
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyding committed Nov 14, 2024
1 parent 49c8f95 commit 91d097c
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
SubaccountUsernamesTable,
SubaccountsWithoutUsernamesResult,
} from '@dydxprotocol-indexer/postgres';
import _ from 'lodash';

import config from '../config';
import { generateUsernameForSubaccount } from '../helpers/usernames-helper';
Expand All @@ -13,6 +14,7 @@ export default async function runTask(): Promise<void> {
SubaccountUsernamesTable.getSubaccountZerosWithoutUsernames(
config.SUBACCOUNT_USERNAME_BATCH_SIZE,
);
let successCount: number = 0;
for (const subaccount of subaccountZerosWithoutUsername) {
for (let i = 0; i < config.ATTEMPT_PER_SUBACCOUNT; i++) {
const username: string = generateUsernameForSubaccount(
Expand All @@ -30,6 +32,7 @@ export default async function runTask(): Promise<void> {
subaccountId: subaccount.subaccountId,
});
// If success, break from loop and move to next subaccount.
successCount += 1;
break;
} catch (e) {
// There are roughly ~225 million possible usernames
Expand Down Expand Up @@ -58,4 +61,16 @@ export default async function runTask(): Promise<void> {
}
}
}
const subaccountAddresses = _.map(
subaccountZerosWithoutUsername,
(subaccount) => subaccount.address,
);

logger.info({
at: 'subaccount-username-generator#runTask',
message: 'Generated usernames',
batchSize: subaccountZerosWithoutUsername.length,
successCount,
addressSample: subaccountAddresses.slice(0, 10),
});
}

0 comments on commit 91d097c

Please sign in to comment.