Skip to content

Commit

Permalink
[TECH] Ecrire dans PG le contenu pédagogique lorsqu'on provoque la cr…
Browse files Browse the repository at this point in the history
…éation d'une nouvelle release (PIX-15470)

 #10667
  • Loading branch information
pix-service-auto-merge authored Nov 28, 2024
2 parents bf9d2c9 + db23366 commit 914a920
Show file tree
Hide file tree
Showing 20 changed files with 2,504 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { JobController } from '../../../shared/application/jobs/job-controller.js';
import { logger } from '../../../shared/infrastructure/utils/logger.js';
import { LcmsCreateReleaseJob } from '../../domain/models/LcmsCreateReleaseJob.js';
import { usecases } from '../../domain/usecases/index.js';

export class LcmsCreateReleaseJobController extends JobController {
constructor() {
super(LcmsCreateReleaseJob.name);
}

async handle() {
try {
await usecases.createLearningContentRelease();
logger.info('Learning Content cache updated with newly created release');
} catch (e) {
logger.error('Error while updating cache with newly created release', e);
throw e;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { sharedUsecases } from '../../shared/domain/usecases/index.js';
import { logger } from '../../shared/infrastructure/utils/logger.js';
import { usecases } from '../domain/usecases/index.js';

const createRelease = async function (request, h) {
sharedUsecases
.createLcmsRelease()
.then(() => {
logger.info('Release created and cache reloaded');
})
.catch((e) => {
logger.error('Error while creating the release and reloading cache', e);
});
return h.response({}).code(204);
const { userId } = request.auth.credentials;
await usecases.scheduleCreateLearningContentReleaseJob({ userId });
return h.response({}).code(202);
};

const refreshCache = async function (request, h) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export async function register(server) {
tags: ['api', 'lcms'],
notes: [
'Cette route est restreinte aux utilisateurs authentifiés avec le rôle Super Admin',
'Elle permet de demander la création d’une nouvelle version au référentiel et de recharger le cache',
'Elle permet de lancer un job pour demander la création d’une nouvelle version au référentiel\n' +
' et de recharger le cache',
],
},
},
Expand Down Expand Up @@ -74,7 +75,8 @@ export async function register(server) {
tags: ['api', 'cache'],
notes: [
'Cette route est restreinte aux utilisateurs authentifiés avec le rôle Super Admin',
'Elle permet de précharger les entrées du cache de l’application (les requêtes les plus longues)',
'Elle permet de lancer un job pour précharger les entrées du cache de l’application \n' +
'(les requêtes les plus longues)',
],
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class LcmsCreateReleaseJob {
constructor({ userId }) {
this.userId = userId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { withTransaction } from '../../../shared/domain/DomainTransaction.js';

export const createLearningContentRelease = withTransaction(
/** @param {import('./dependencies.js').Dependencies} */
async function createLearningContentRelease({
LearningContentCache,
frameworkRepository,
areaRepository,
competenceRepository,
thematicRepository,
tubeRepository,
challengeRepository,
skillRepository,
courseRepository,
tutorialRepository,
missionRepository,
}) {
const learningContent = await LearningContentCache.instance.update();

await frameworkRepository.save(learningContent.frameworks);
await areaRepository.save(learningContent.areas);
await competenceRepository.save(learningContent.competences);
await thematicRepository.save(learningContent.thematics);
await tubeRepository.save(learningContent.tubes);
await skillRepository.save(learningContent.skills);
await challengeRepository.save(learningContent.challenges);
await courseRepository.save(learningContent.courses);
await tutorialRepository.save(learningContent.tutorials);
await missionRepository.save(learningContent.missions);
},
);
2 changes: 2 additions & 0 deletions api/src/learning-content/domain/usecases/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { challengeRepository } from '../../infrastructure/repositories/challenge
import { competenceRepository } from '../../infrastructure/repositories/competence-repository.js';
import { courseRepository } from '../../infrastructure/repositories/course-repository.js';
import { frameworkRepository } from '../../infrastructure/repositories/framework-repository.js';
import { lcmsCreateReleaseJobRepository } from '../../infrastructure/repositories/jobs/lcms-create-release-job-repository.js';
import { lcmsRefreshCacheJobRepository } from '../../infrastructure/repositories/jobs/lcms-refresh-cache-job-repository.js';
import { missionRepository } from '../../infrastructure/repositories/mission-repository.js';
import { skillRepository } from '../../infrastructure/repositories/skill-repository.js';
Expand All @@ -23,6 +24,7 @@ export const dependencies = {
tutorialRepository,
missionRepository,
lcmsRefreshCacheJobRepository,
lcmsCreateReleaseJobRepository,
LearningContentCache,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { LcmsCreateReleaseJob } from '../models/LcmsCreateReleaseJob.js';

/**
* @param {{
* userId: number
* } & import('./dependencies.js').Dependencies}
*/
export async function scheduleCreateLearningContentReleaseJob({ userId, lcmsCreateReleaseJobRepository }) {
await lcmsCreateReleaseJobRepository.performAsync(new LcmsCreateReleaseJob({ userId }));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { JobRepository, JobRetry } from '../../../../shared/infrastructure/repositories/jobs/job-repository.js';
import { LcmsCreateReleaseJob } from '../../../domain/models/LcmsCreateReleaseJob.js';

class LcmsCreateReleaseJobRepository extends JobRepository {
constructor() {
super({
name: LcmsCreateReleaseJob.name,
retry: JobRetry.NO_RETRY,
});
}
}

export const lcmsCreateReleaseJobRepository = new LcmsCreateReleaseJobRepository();
3 changes: 0 additions & 3 deletions api/src/shared/domain/usecases/create-lcms-release.js

This file was deleted.

Loading

0 comments on commit 914a920

Please sign in to comment.