Skip to content

Commit

Permalink
Remove functionality for updating students individually (#4489)
Browse files Browse the repository at this point in the history
  • Loading branch information
valtterikantanen committed Jun 17, 2024
1 parent 5f33234 commit 7abd945
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 47 deletions.
6 changes: 0 additions & 6 deletions services/backend/src/routes/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const {
updateSISRedisCache,
updateSISStudents,
updateStudentsByStudentNumber,
updateStudentsIndividually,
} = require('../services/sisUpdaterService')
const logger = require('../util/logger')
const { jobMaker, getJobs } = require('../worker/queue')
Expand Down Expand Up @@ -38,11 +37,6 @@ router.get('/update/v2/students', async (_req, res) => {
}
})

router.get('/update/v2/students_individually', async (_req, res) => {
await updateStudentsIndividually()
res.status(200).send()
})

router.post('/update/v2/customlist/:type', async (req, res) => {
const { type } = req.params
const list = req.body
Expand Down
35 changes: 1 addition & 34 deletions services/backend/src/services/sisUpdaterService.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ const axios = require('axios')
const { Op } = require('sequelize')

const { SIS_UPDATER_URL, SECRET_TOKEN } = require('../conf-backend')
const { Studyplan, Student, StudyrightElement } = require('../models')
const logger = require('../util/logger')
const { Studyplan } = require('../models')

const client = axios.create({ baseURL: SIS_UPDATER_URL })

Expand Down Expand Up @@ -40,37 +39,6 @@ const updateSISRedisCache = async () => {
const response = await client.get('/v1/rediscache', params)
return response.data
}
const delay = time => {
return new Promise(res => {
setTimeout(res, time)
})
}

const updateStudentsIndividually = async () => {
try {
const studentNumbers = await Student.findAll({
attributes: ['studentnumber'],
include: {
model: StudyrightElement,
where: {
code: { [Op.regexp]: '(KH*|MH*)' },
},
},
})
const uniqueStudents = [...new Set(studentNumbers.map(s => s.studentnumber))]
const chunkSize = 4000
for (let from = 0; from < uniqueStudents.length - chunkSize; from += chunkSize) {
await client.post(
'v1/students',
{ studentnumbers: uniqueStudents.slice(from, from + chunkSize), individualMode: true },
params
)
await delay(200)
}
} catch (e) {
logger.error(e)
}
}

const studyplansUpdate = async days => {
const limitDate = new Date()
Expand Down Expand Up @@ -100,5 +68,4 @@ module.exports = {
abort,
updateCoursesByCourseCode,
studyplansUpdate,
updateStudentsIndividually,
}
2 changes: 0 additions & 2 deletions services/frontend/src/components/Updater/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const Updater = () => {

const updateSISMeta = () => apiCall('meta', '/updater/update/v2/meta', 'get')
const updateSISStudents = () => apiCall('students', '/updater/update/v2/students', 'get')
const updateSISStudentsIndividually = () => apiCall('students', '/updater/update/v2/students_individually', 'get')
const updateSISProgrammes = () => apiCall('curriculums', '/updater/update/v2/programmes')
const updateSISCustomList = () =>
apiCall('custom list', `/updater/update/v2/customlist/${type}`, 'post', customList.trim().split('\n'))
Expand Down Expand Up @@ -99,7 +98,6 @@ export const Updater = () => {
<Form.Group>
<Form.Button content="Update meta" onClick={updateSISMeta} />
<Form.Button content="Update students" onClick={updateSISStudents} />
<Form.Button content="Update students individually (don't click)" onClick={updateSISStudentsIndividually} />
<Form.Button
content="Update curriculums"
onClick={() => {
Expand Down
4 changes: 2 additions & 2 deletions updater/sis-updater-scheduler/src/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,13 @@ const getHourlyPersonsToUpdate = async () => {
)
}

const scheduleByStudentNumbers = async (studentNumbers, individualMode = false) => {
const scheduleByStudentNumbers = async studentNumbers => {
logger.info('Scheduling by student numbers')
const { knex } = knexConnection
const personsToUpdate = await knex('persons').column('id', 'student_number').whereIn('student_number', studentNumbers)

await eachLimit(
chunk(personsToUpdate, individualMode ? 1 : CHUNK_SIZE),
chunk(personsToUpdate, CHUNK_SIZE),
10,
async s => await createJobs(s, 'students', SIS_MISC_SCHEDULE_CHANNEL)
)
Expand Down
5 changes: 2 additions & 3 deletions updater/sis-updater-scheduler/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,11 @@ app.get('/v1/programmes', async (_, res) => {
})

app.post('/v1/students', async (req, res) => {
const { individualMode } = req.body
const studentnumbers = req.body.studentnumbers.map(n => (n[0] === '0' ? n : `0${n}`))

logger.info(`Scheduling ${studentnumbers.length} custom studentnumbers ${individualMode ? 'individually' : ''}`)
logger.info(`Scheduling ${studentnumbers.length} custom studentnumbers`)

await scheduleByStudentNumbers(studentnumbers, individualMode)
await scheduleByStudentNumbers(studentnumbers)
res.locals.msg('Scheduled studentnumbers')
})

Expand Down

0 comments on commit 7abd945

Please sign in to comment.