Skip to content

Commit

Permalink
feat(authorization): add "soft" param to trigger re-indexing without …
Browse files Browse the repository at this point in the history
…index wipe (#1116)

chore(authorization): rename job logs to better show completed operations
  • Loading branch information
kkopanidis authored Aug 28, 2024
1 parent b272286 commit d01c516
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
23 changes: 17 additions & 6 deletions modules/authorization/src/admin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import {
ParsedRouterRequest,
UnparsedRouterResponse,
} from '@conduitplatform/grpc-sdk';
import { GrpcServer, RoutingManager } from '@conduitplatform/module-tools';
import {
ConduitBoolean,
GrpcServer,
RoutingManager,
} from '@conduitplatform/module-tools';
import { ResourceHandler } from './resources.js';
import { RelationHandler } from './relations.js';
import {
Expand All @@ -15,6 +19,7 @@ import {
ResourceDefinition,
} from '../models/index.js';
import { QueueController } from '../controllers/index.js';
import { isNil } from 'lodash-es';

export class AdminHandlers {
private readonly resourceHandler: ResourceHandler;
Expand All @@ -37,11 +42,14 @@ export class AdminHandlers {
) {
// used to trigger an index re-construction
ConduitGrpcSdk.Logger.warn('Reconstructing indices...');
ConduitGrpcSdk.Logger.warn('Wiping index data...');
await Promise.all([
ActorIndex.getInstance().deleteMany({}),
ObjectIndex.getInstance().deleteMany({}),
]);
if (isNil(call.request.bodyParams.soft) || call.request.bodyParams.soft === false) {
ConduitGrpcSdk.Logger.warn('Wiping index data...');
await Promise.all([
ActorIndex.getInstance().deleteMany({}),
ObjectIndex.getInstance().deleteMany({}),
]);
}

callback('ok');
ConduitGrpcSdk.Logger.warn('Beginning index reconstruction...');
const resources = await ResourceDefinition.getInstance().findMany({});
Expand Down Expand Up @@ -88,6 +96,9 @@ export class AdminHandlers {
{
path: '/indexer/reconstruct',
action: ConduitRouteActions.POST,
bodyParams: {
soft: ConduitBoolean.Optional,
},
description: `Wipes and re-constructs the relation indexes.`,
},
new ConduitRouteReturnDefinition('IndexReconstruct', 'String'),
Expand Down
8 changes: 4 additions & 4 deletions modules/authorization/src/controllers/queue.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ export class QueueController {
// autorun: true,
});
worker.on('active', job => {
ConduitGrpcSdk.Logger.info(`Job ${job.id} started`);
ConduitGrpcSdk.Logger.info(`Index ${job.id} started`);
});
worker.on('completed', job => {
ConduitGrpcSdk.Logger.info(`Job ${job.id} completed`);
ConduitGrpcSdk.Logger.info(`Index ${job.id} completed`);
});
worker.on('error', (error: Error) => {
ConduitGrpcSdk.Logger.error(`Job error:`);
Expand Down Expand Up @@ -84,10 +84,10 @@ export class QueueController {
// autorun: true,
});
worker.on('active', job => {
ConduitGrpcSdk.Logger.info(`Job ${job.id} started`);
ConduitGrpcSdk.Logger.info(`Connection ${job.id} started`);
});
worker.on('completed', job => {
ConduitGrpcSdk.Logger.info(`Job ${job.id} completed`);
ConduitGrpcSdk.Logger.info(`Connection ${job.id} completed`);
});
worker.on('error', error => {
ConduitGrpcSdk.Logger.error(`Job error:`);
Expand Down

0 comments on commit d01c516

Please sign in to comment.