-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend): add working summarize
- Loading branch information
Showing
35 changed files
with
683 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'reflect-metadata'; | ||
|
||
import { pipe } from 'fp-ts/lib/function'; | ||
import { container } from 'tsyringe'; | ||
|
||
import { runTaskAsVoid, tapTaskEitherTE, tryOrThrowTE } from '@llm/commons'; | ||
import { DatabaseConnectionRepo, ElasticsearchRepo } from '~/modules'; | ||
import { ProjectsSummariesService } from '~/modules/projects-summaries'; | ||
|
||
const databaseConnectionRepo = container.resolve(DatabaseConnectionRepo); | ||
const esConnection = container.resolve(ElasticsearchRepo); | ||
|
||
const summariesService = container.resolve(ProjectsSummariesService); | ||
|
||
void pipe( | ||
summariesService.summarizeAllProjects(), | ||
tapTaskEitherTE(() => esConnection.close), | ||
tapTaskEitherTE(() => databaseConnectionRepo.close), | ||
tryOrThrowTE, | ||
runTaskAsVoid, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export * from './projects-summaries.config'; | ||
export * from './projects-summaries.cron'; | ||
export * from './projects-summaries.errors'; | ||
export * from './projects-summaries.repo'; | ||
export * from './projects-summaries.service'; | ||
export * from './projects-summaries.tables'; |
7 changes: 7 additions & 0 deletions
7
apps/backend/src/modules/projects-summaries/projects-summaries.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { z } from 'zod'; | ||
|
||
export const ProjectsSummariesConfigV = z.object({ | ||
cron: z.string().default('*/20 * * * * *'), | ||
}); | ||
|
||
export type ProjectsSummariesConfigT = z.infer<typeof ProjectsSummariesConfigV>; |
46 changes: 46 additions & 0 deletions
46
apps/backend/src/modules/projects-summaries/projects-summaries.cron.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { flow } from 'fp-ts/lib/function'; | ||
import { inject, injectable } from 'tsyringe'; | ||
|
||
import { runTaskAsVoid, tryOrThrowTE } from '@llm/commons'; | ||
import { ConfigService } from '~/modules/config'; | ||
|
||
import { CronJob, CronService } from '../cron'; | ||
import { LoggerService } from '../logger'; | ||
import { ProjectsSummariesService } from './projects-summaries.service'; | ||
|
||
@injectable() | ||
export class ProjectSummariesCronJob extends CronJob { | ||
private readonly logger = LoggerService.of('ProjectSummariesCronJob'); | ||
|
||
constructor( | ||
@inject(CronService) cronService: CronService, | ||
@inject(ConfigService) configService: ConfigService, | ||
@inject(ProjectsSummariesService) private readonly projectsSummariesService: ProjectsSummariesService, | ||
) { | ||
super(cronService, configService); | ||
} | ||
|
||
registerCronJob(): void { | ||
const { logger } = this; | ||
const { cron } = this.config.projectsSummaries; | ||
|
||
if (!cron) { | ||
logger.warn('ProjectSummariesCronJob cron job is disabled!'); | ||
return; | ||
} | ||
|
||
this.cronService.tryRegister( | ||
{ | ||
expression: cron, | ||
skipIfPreviousJobNotDone: true, | ||
}, | ||
flow( | ||
this.projectsSummariesService.summarizeAllProjects, | ||
tryOrThrowTE, | ||
runTaskAsVoid, | ||
), | ||
); | ||
|
||
logger.info('Registered ProjectSummariesCronJob cron job!'); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
apps/backend/src/modules/projects-summaries/projects-summaries.errors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { SdKSearchMessagesOutputT } from '@llm/sdk'; | ||
|
||
import { TaggedError } from '@llm/commons'; | ||
|
||
export class MissingAIModelInProjectError | ||
extends TaggedError.ofLiteral<SdKSearchMessagesOutputT>()('MissingAIModelInProject') { | ||
} |
Oops, something went wrong.