Skip to content

Commit

Permalink
fix: queue build
Browse files Browse the repository at this point in the history
  • Loading branch information
Joabesv committed Dec 28, 2023
1 parent 491b948 commit 8d48086
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 39 deletions.
2 changes: 1 addition & 1 deletion apps/queue/src/helpers/resolveProfessors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function resolveProfessors(
return null;
}
const isTeacherPresent = (t: Teacher) =>
t.name === normalizedName ?? (t.alias || []).includes(normalizedName);
t.name === normalizedName || (t.alias || []).includes(normalizedName);
const foundTeacher = teachers.find((teacher) => isTeacherPresent(teacher));

if (foundTeacher) {
Expand Down
74 changes: 36 additions & 38 deletions apps/queue/src/jobs/enrollments/updateEnrollments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,44 @@ type UpdateEnrollments = {
};

function updateEnrollments(data: any) {
const data = payload.json;
logger.info({ msg: 'qual a fitaaaaa', data });
// const updateEnrollment = async (enrollment: EnrollmentDocument) => {
// const keys = ['ra', 'year', 'quad', 'disciplina'] as const;
const updateEnrollment = async (enrollment: EnrollmentDocument) => {
const keys = ['ra', 'year', 'quad', 'disciplina'] as const;
const enrollmentModel: any = {};
const key = {
ra: enrollment.ra,
year: enrollment.year,
quad: enrollment.quad,
disciplina: enrollment.disciplina,
};

// const key = {
// ra: enrollment.ra,
// year: enrollment.year,
// quad: enrollment.quad,
// disciplina: enrollment.disciplina,
// };
// TODO: remove any later
const identifier = generateIdentifier(key, keys as any);

// // TODO: remove any later
// const identifier = generateIdentifier(key, keys as any);

// try {
// const insertOpts = { new: true, upsert: true };
// const {
// ra,
// year,
// quad,
// disciplina,
// identifier: ignored,
// _id,
// ...updateData
// } = enrollment;
// // this piece of code right here is a MASSIVE query
// // for the record: since its inserting it needs to be a document and being a document means
// // it has and _id
// await enrollmentModel.findOneAndUpdate(
// { identifier },
// { $set: updateData },
// insertOpts,
// );
// } catch (error) {
// logger.error(error);
// throw error;
// }
// };
try {
const insertOpts = { new: true, upsert: true };
const {
ra,
year,
quad,
disciplina,
identifier: ignored,
_id,
...updateData
} = enrollment;
// this piece of code right here is a MASSIVE query
// for the record: since its inserting it needs to be a document and being a document means
// it has and _id
await enrollmentModel.findOneAndUpdate(
{ identifier },
{ $set: updateData },
insertOpts,
);
} catch (error) {
logger.error(error);
throw error;
}
};

return asyncParallelMap(data, updateEnrollment, 10);
}
Expand All @@ -57,14 +56,13 @@ export const updateEnrollmentsQueue = createQueue('Update:Enrollments');
export const addEnrollmentsToQueue = async (
payload: Job<UpdateEnrollments>,
) => {
logger.info({ msg: 'added to queu', payload });
await updateEnrollmentsQueue.add('Update:Enrollments', payload);
};

export const updateEnrollmentsWorker = async (job: Job<UpdateEnrollments>) => {
try {
const payload = job.data;
updateEnrollments(payload).catch((error) => logger.info(error));
await updateEnrollments(payload);
} catch (error) {
logger.error(
{ error },
Expand Down

0 comments on commit 8d48086

Please sign in to comment.