Skip to content

Commit 57f9208

Browse files
feat: create script to schedule adding Pending Summaries To Queue instead of Cron (#66)
1 parent e37716a commit 57f9208

File tree

9 files changed

+61
-6
lines changed

9 files changed

+61
-6
lines changed

apps/api/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ RUN npm run build
2626
EXPOSE 3000
2727

2828
# Command to start your NestJS application
29-
CMD ["node", "dist/main.js"]
29+
CMD ./scheduler.sh & node dist/main.js

apps/api/docs/development-setup.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ sudo systemctl status mariadb
6868
GPT_MODEL="gpt-4o"
6969
7070
# Docker env
71-
COMPOSE_PROJECT_NAME=transcript-summarizer-api
71+
COMPOSE_PROJECT_NAME=transcript-summarizer-api
7272
```
7373

7474
Alternatively, use the `.env.example` file instead.
@@ -92,3 +92,11 @@ sudo systemctl status mariadb
9292
```
9393

9494
Transcript Summarizer API will now be running locally at `http://localhost:3000`.
95+
96+
6. Run the scheduler script:
97+
98+
```sh
99+
./scheduler.sh
100+
```
101+
102+
This should start the service function that adds all pending summaries to queue for processing.

apps/api/docs/usage-guide.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Follow the development setup guides for API and portal to set up the codebase be
4242
## 3. Using the Transcript Summarizer Portal
4343

4444
1. **Start the API**
45+
Run the scheduler script (see [Codebase Setup](#codebase) for details).
4546
2. **Start the Portal**
4647
The Transcript Summarizer Portal should now be running locally at:
4748
- `http://localhost:4200` (Standard setup)
@@ -68,7 +69,7 @@ When using the API, you'll need to set your **Microsoft authentication token** a
6869

6970
### Getting your Microsoft authentication token
7071

71-
1. Start the API
72+
1. Start the API and scheduler (see [Codebase Setup](#codebase) for details).
7273
2. Start the Portal
7374
3. Transcript Summarizer Portal should be running locally at `http://localhost:4200` (or `http://localhost:5000` for docker setup).
7475
4. Open the portal URL. You will be prompted to log in to your Microsoft account.

apps/api/scheduler.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
SCHEDULE_TIME=1
4+
5+
source ".env"
6+
7+
BASE_URL="http://localhost:${SERVER_PORT}/summary"
8+
9+
add_pending_summaries_to_queue() {
10+
curl -X POST "${BASE_URL}/schedule" -H "Content-Type: application/json" -d '{}'
11+
}
12+
13+
while true; do
14+
add_pending_summaries_to_queue
15+
sleep $SCHEDULE_TIME
16+
done

apps/api/src/config/logger.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const transportsConfig = [
3535
format: format.combine(
3636
format.timestamp(),
3737
format.ms(),
38-
nestWinstonModuleUtilities.format.nestLike('OsmosysAssistant'),
38+
nestWinstonModuleUtilities.format.nestLike('TranscriptSummarizer'),
3939
),
4040
}),
4141

apps/api/src/modules/summary/schedule/schedule.service.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Injectable, Logger, OnModuleInit, OnModuleDestroy } from '@nestjs/common';
2-
import { Cron, CronExpression } from '@nestjs/schedule';
32
import { SummaryService } from '../summary.service';
43
import { ConfigService } from '@nestjs/config';
54
import Redis from 'ioredis';
@@ -22,7 +21,6 @@ export class ScheduleService implements OnModuleInit, OnModuleDestroy {
2221
});
2322
}
2423

25-
@Cron(CronExpression.EVERY_SECOND)
2624
async addSummaryToQueue(): Promise<void> {
2725
if (this.isProcessing) {
2826
return;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Test, TestingModule } from '@nestjs/testing';
2+
import { SummaryController } from './summary.controller';
3+
4+
describe('SummaryController', () => {
5+
let controller: SummaryController;
6+
7+
beforeEach(async () => {
8+
const module: TestingModule = await Test.createTestingModule({
9+
controllers: [SummaryController],
10+
}).compile();
11+
12+
controller = module.get<SummaryController>(SummaryController);
13+
});
14+
15+
it('should be defined', () => {
16+
expect(controller).toBeDefined();
17+
});
18+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Controller, Post } from '@nestjs/common';
2+
import { ScheduleService } from './schedule/schedule.service';
3+
4+
@Controller('summary')
5+
export class SummaryController {
6+
constructor(private readonly scheduleService: ScheduleService) {}
7+
8+
@Post('schedule')
9+
async addPendingSummariesToQueue(): Promise<void> {
10+
this.scheduleService.addSummaryToQueue();
11+
}
12+
}

apps/api/src/modules/summary/summary.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ScheduleService } from './schedule/schedule.service';
1010
import { ConfigService } from '@nestjs/config';
1111
import { summaryQueueConfig } from './queues/summary.queue';
1212
import { MeetingSummaryService } from 'src/modules/summary/summarizer/summarizer.service';
13+
import { SummaryController } from './summary.controller';
1314

1415
@Module({
1516
imports: [TypeOrmModule.forFeature([Summary]), BullModule.registerQueue(summaryQueueConfig)],
@@ -23,5 +24,6 @@ import { MeetingSummaryService } from 'src/modules/summary/summarizer/summarizer
2324
MeetingSummaryService,
2425
],
2526
exports: [SummaryService, MeetingSummaryService],
27+
controllers: [SummaryController],
2628
})
2729
export class SummaryModule {}

0 commit comments

Comments
 (0)