Skip to content

Commit

Permalink
Sync users only manually in dev env
Browse files Browse the repository at this point in the history
  • Loading branch information
joonashak committed Aug 4, 2023
1 parent 7f1f2ff commit 9c0252e
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app-nest/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { TypeOrmModule } from "@nestjs/typeorm";
import { BoltModule } from "./bolt/bolt.module";
import configuration from "./config/configuration";
import { inDevelopmentEnvironment } from "./config/utils";
import { DevToolsModule } from "./dev-tools/dev-tools.module";
import { EntitiesModule } from "./entities/entities.module";
import { GuiModule } from "./gui/gui.module";
import { SyncModule } from "./sync/sync.module";
Expand All @@ -27,6 +28,7 @@ import { SyncModule } from "./sync/sync.module";
GuiModule,
EntitiesModule,
SyncModule,
DevToolsModule,
],
})
export class AppModule {}
16 changes: 16 additions & 0 deletions app-nest/src/dev-tools/dev-tools.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Controller } from "@nestjs/common";
import BoltAction from "../bolt/decorators/bolt-action.decorator";
import { UserSyncService } from "../sync/user-sync.service";

@Controller()
export class DevToolsController {
constructor(private userSyncService: UserSyncService) {}

@BoltAction("sync_users")
syncUsers() {
return async ({ ack }) => {
await ack();
await this.userSyncService.syncUsers();
};
}
}
6 changes: 6 additions & 0 deletions app-nest/src/dev-tools/dev-tools.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Module } from "@nestjs/common";
import { SyncModule } from "../sync/sync.module";
import { DevToolsController } from "./dev-tools.controller";

@Module({ imports: [SyncModule], controllers: [DevToolsController] })
export class DevToolsModule {}
12 changes: 10 additions & 2 deletions app-nest/src/gui/dev/dev-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ const devTools = [
text: {
type: "plain_text",
text: ":recycle: Sync Users",
emoji: true,
},
value: "sync_users",
action_id: "sync_users",
},
],
},
{
type: "context",
elements: [
{
type: "plain_text",
text: "In development environment, users are not synchronized between local database and Slack on app start to avoid running into API rate limits due to hot-reloads. Sync users manually when necessary.",
},
],
},
Expand Down
1 change: 1 addition & 0 deletions app-nest/src/sync/sync.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ import { UserSyncService } from "./user-sync.service";
@Module({
imports: [UserModule],
providers: [SyncService, UserSyncService, UserService],
exports: [SyncService, UserSyncService],
})
export class SyncModule {}
7 changes: 5 additions & 2 deletions app-nest/src/sync/sync.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Injectable, OnApplicationBootstrap } from "@nestjs/common";
import { inDevelopmentEnvironment } from "../config/utils";
import { UserSyncService } from "./user-sync.service";

@Injectable()
export class SyncService implements OnApplicationBootstrap {
constructor(private userSyncService: UserSyncService) {}

async onApplicationBootstrap() {
console.log("app bootstrap");
await this.userSyncService.syncUsers();
if (!inDevelopmentEnvironment) {
await this.userSyncService.syncUsers();
}
}
}
1 change: 0 additions & 1 deletion app-nest/src/sync/user-sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export class UserSyncService {
) {}

async syncUsers() {
// FIXME: This needs to be limited in dev env to protect against rate-limit errors. Add UI button to fire this manually.
this.logger.log("Starting user data synchronization.");
const data = await this.boltUserService.getUsers();

Expand Down

0 comments on commit 9c0252e

Please sign in to comment.