Skip to content

Commit 0c093c4

Browse files
committed
fix: use jobId instead of projectId to find job
1 parent 1041679 commit 0c093c4

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

src/eventHandlers/JobEventHandler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async function cancelJob (payload) {
2525
return
2626
}
2727
if (payload.value.status !== 'cancelled') {
28-
logger.info({
28+
logger.debug({
2929
component: 'JobEventHandler',
3030
context: 'cancelJob',
3131
message: `not interested job - status: ${payload.value.status}`

src/eventHandlers/ResourceBookingEventHandler.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ async function selectJobCandidate (jobId, userId) {
4545
/**
4646
* Update the status of the Job to assigned when it positions requirement is fullfilled.
4747
*
48-
* @param {Object} job the job data
48+
* @param {String} jobId the job id
4949
* @returns {undefined}
5050
*/
51-
async function assignJob (job) {
51+
async function assignJob (jobId) {
52+
const job = await models.Job.findById(jobId)
5253
if (job.status === 'assigned') {
53-
logger.info({
54+
logger.debug({
5455
component: 'ResourceBookingEventHandler',
5556
context: 'assignJob',
5657
message: `job with projectId ${job.projectId} is already assigned`
@@ -59,6 +60,7 @@ async function assignJob (job) {
5960
}
6061
const resourceBookings = await models.ResourceBooking.findAll({
6162
where: {
63+
jobId: job.id,
6264
status: 'assigned',
6365
deletedAt: null
6466
}
@@ -70,7 +72,7 @@ async function assignJob (job) {
7072
})
7173
if (job.numPositions === resourceBookings.length) {
7274
await JobService.partiallyUpdateJob(helper.getAuditM2Muser(), job.id, { status: 'assigned' })
73-
logger.info({ component: 'ResourceBookingEventHandler', context: 'assignJob', message: `job with projectId ${job.projectId} is assigned` })
75+
logger.info({ component: 'ResourceBookingEventHandler', context: 'assignJob', message: `job ${job.id} is assigned` })
7476
}
7577
}
7678

@@ -90,24 +92,24 @@ async function processUpdate (payload) {
9092
return
9193
}
9294
if (payload.value.status !== 'assigned') {
93-
logger.info({
95+
logger.debug({
9496
component: 'ResourceBookingEventHandler',
9597
context: 'processUpdate',
9698
message: `not interested resource booking - status: ${payload.value.status}`
9799
})
98100
return
99101
}
100102
const resourceBooking = await models.ResourceBooking.findById(payload.value.id)
101-
const jobs = await models.Job.findAll({
102-
where: {
103-
projectId: resourceBooking.projectId,
104-
deletedAt: null
105-
}
106-
})
107-
for (const job of jobs) {
108-
await selectJobCandidate(job.id, resourceBooking.userId)
109-
await assignJob(job)
103+
if (!resourceBooking.jobId) {
104+
logger.debug({
105+
component: 'ResourceBookingEventHandler',
106+
context: 'processUpdate',
107+
message: `id: ${resourceBooking.id} resource booking without jobId - ignored`
108+
})
109+
return
110110
}
111+
await selectJobCandidate(resourceBooking.jobId, resourceBooking.userId)
112+
await assignJob(resourceBooking.jobId)
111113
}
112114

113115
module.exports = {

src/eventHandlers/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ const TopicOperationMapping = {
2222
*/
2323
async function handleEvent (topic, payload) {
2424
if (!TopicOperationMapping[topic]) {
25-
logger.info({ component: 'eventHanders', context: 'handleEvent', message: `not interested event - topic: ${topic}` })
25+
logger.debug({ component: 'eventHanders', context: 'handleEvent', message: `not interested event - topic: ${topic}` })
2626
return
2727
}
28+
logger.info({ component: 'eventHanders', context: 'handleEvent', message: `event handling - topic: ${topic}` })
2829
logger.debug({ component: 'eventHanders', context: 'handleEvent', message: `handling event - topic: ${topic} - payload: ${JSON.stringify(payload)}` })
2930
try {
3031
await TopicOperationMapping[topic](payload)
@@ -33,7 +34,7 @@ async function handleEvent (topic, payload) {
3334
// throw error so that it can be handled by the app
3435
throw err
3536
}
36-
logger.info({ component: 'eventHanders', context: 'handleEvent', message: 'event successfully handled' })
37+
logger.info({ component: 'eventHanders', context: 'handleEvent', message: `event successfully handled - topic: ${topic}` })
3738
}
3839

3940
/**

0 commit comments

Comments
 (0)