Skip to content

Commit

Permalink
Add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
thomtrp committed Jun 4, 2024
1 parent 9f1a8ce commit 6863972
Showing 1 changed file with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ export class RecordPositionBackfillService {
) {}

async backfill(workspaceId: string, dryRun: boolean) {
this.logger.log(
`Starting backfilling record positions for workspace ${workspaceId}`,
);

const dataSourceSchema =
this.workspaceDataSourceService.getSchemaName(workspaceId);

Expand All @@ -34,7 +38,7 @@ export class RecordPositionBackfillService {

for (const objectMetadata of objectMetadataWithPosition) {
const [recordsWithoutPositionQuery, recordsWithoutPositionQueryParams] =
await this.recordPositionQueryFactory.create(
this.recordPositionQueryFactory.create(
{
recordPositionQueryType: RecordPositionQueryType.FIND_BY_POSITION,
positionValue: null,
Expand All @@ -48,12 +52,21 @@ export class RecordPositionBackfillService {
recordsWithoutPositionQuery,
recordsWithoutPositionQueryParams,
workspaceId,
undefined,
);

if (recordsWithoutPosition.length === 0) {
this.logger.log(
`No records without position for ${objectMetadata.nameSingular}`,
);
continue;
}

const position = await this.recordPositionFactory.create(
'last',
objectMetadata as ObjectMetadataInterface,
{
isCustom: objectMetadata.isCustom,
nameSingular: objectMetadata.nameSingular,
},
workspaceId,
);

Expand All @@ -63,6 +76,14 @@ export class RecordPositionBackfillService {
recordIndex++
) {
const recordId = recordsWithoutPosition[recordIndex].id;

if (!recordId) {
this.logger.log(
`Fetched record without id for ${objectMetadata.nameSingular}`,
);
continue;
}

const backfilledPosition = position + recordIndex;

this.logger.log(
Expand All @@ -73,7 +94,7 @@ export class RecordPositionBackfillService {
continue;
}

const [query, params] = await this.recordPositionQueryFactory.create(
const [query, params] = this.recordPositionQueryFactory.create(
{
recordPositionQueryType: RecordPositionQueryType.UPDATE_POSITION,
recordId: recordsWithoutPosition[recordIndex].id,
Expand All @@ -87,7 +108,6 @@ export class RecordPositionBackfillService {
query,
params,
workspaceId,
undefined,
);
}
}
Expand Down

0 comments on commit 6863972

Please sign in to comment.