Skip to content

[PROD] Patch 1.5.3.1 #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions config/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* The default configuration file.
*/

module.exports = {
zapier: {
ZAPIER_SWITCH: process.env.ZAPIER_SWITCH || 'ON',
ZAPIER_JOB_CANDIDATE_SWITCH: process.env.ZAPIER_JOB_CANDIDATE_SWITCH || 'ON'
}
}
181 changes: 181 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@
"create-index": "node src/scripts/createIndex.js",
"delete-index": "node src/scripts/deleteIndex.js",
"view-data": "node src/scripts/view-data.js",
"test": "mocha test/unit/test.js --require test/unit/prepare.js --timeout 20000 --exit",
"test:cov": "nyc --reporter=html --reporter=text mocha test/unit/test.js --require test/unit/prepare.js --timeout 20000 --exit",
"e2e": "mocha test/e2e/test.js --timeout 20000 --exit",
"e2e:cov": "nyc --reporter=html --reporter=text mocha test/e2e/test.js --timeout 20000 --exit"
"test": "cross-env NODE_ENV=test mocha test/unit/test.js --require test/unit/prepare.js --timeout 20000 --exit",
"test:cov": "cross-env NODE_ENV=test nyc --reporter=html --reporter=text mocha test/unit/test.js --require test/unit/prepare.js --timeout 20000 --exit",
"e2e": "cross-env NODE_ENV=test mocha test/e2e/test.js --timeout 20000 --exit",
"e2e:cov": "cross-env NODE_ENV=test nyc --reporter=html --reporter=text mocha test/e2e/test.js --timeout 20000 --exit"
},
"author": "TCSCODER",
"license": "none",
"devDependencies": {
"cross-env": "^7.0.3",
"mocha": "^7.1.2",
"mocha-prepare": "^0.1.0",
"nock": "^12.0.3",
"nyc": "^14.1.1",
"should": "^13.2.3",
"sinon": "^10.0.1",
"standard": "^12.0.1",
"stringcase": "^4.3.1",
"superagent": "^5.1.0"
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ global.Promise = require('bluebird')

Joi.rateType = () => Joi.string().valid('hourly', 'daily', 'weekly', 'monthly')
Joi.jobStatus = () => Joi.string().valid('sourcing', 'in-review', 'assigned', 'closed', 'cancelled')
Joi.jobCandidateStatus = () => Joi.string().valid('open', 'selected', 'shortlist', 'rejected', 'cancelled', 'interview')
Joi.jobCandidateStatus = () => Joi.string().valid('open', 'selected', 'shortlist', 'rejected', 'cancelled', 'interview', 'topcoder-rejected')
Joi.workload = () => Joi.string().valid('full-time', 'fractional')
Joi.title = () => Joi.string().max(128)
// Empty string is not allowed by Joi by default and must be enabled with allow('').
Expand Down
16 changes: 16 additions & 0 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ function getESClient () {
}
}

// get document or catch not found error
esClient.getExtra = async function (data) {
let doc

try {
doc = await esClient.getSource(data)
} catch (err) {
if (err.statusCode === 404) {
throw new Error(`id: ${data.id} "${data.index}" not found`)
}
throw err
}

return doc
}

// delete document or catch not found error
esClient.deleteExtra = async function (data) {
try {
Expand Down
19 changes: 13 additions & 6 deletions src/services/JobCandidateProcessorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const localLogger = {
* @param {Object} message the message object
* @returns {undefined}
*/
async function updateCandidateStatus ({ type, payload }) {
if (!payload.status) {
localLogger.debug({ context: 'updateCandidateStatus', message: 'status not updated' })
async function updateCandidateStatus ({ type, payload, previousData }) {
if (previousData.status === payload.status) {
localLogger.debug({ context: 'updateCandidateStatus', message: `jobCandidate is already in status: ${payload.status}` })
return
}
if (!['rejected', 'shortlist'].includes(payload.status)) {
Expand Down Expand Up @@ -56,13 +56,13 @@ async function updateCandidateStatus ({ type, payload }) {
* @param {Object} message the message object
* @returns {undefined}
*/
async function postMessageToZapier ({ type, payload }) {
async function postMessageToZapier ({ type, payload, previousData }) {
if (config.zapier.ZAPIER_JOB_CANDIDATE_SWITCH === constants.Zapier.Switch.OFF) {
localLogger.debug({ context: 'postMessageToZapier', message: 'Zapier Switch off via config, no messages sent' })
return
}
if (type === constants.Zapier.MessageType.JobCandidateUpdate) {
await updateCandidateStatus({ type, payload })
await updateCandidateStatus({ type, payload, previousData })
return
}
throw new Error(`unrecognized message type: ${type}`)
Expand Down Expand Up @@ -113,6 +113,12 @@ processCreate.schema = {
*/
async function processUpdate (message, transactionId) {
const data = message.payload
// save previous data for Zapier logic
// NOTE: ideally if we update Kafka event message to have both: pervious and updated value so we don't have to request it again
const { body: previousData } = await esClient.getExtra({
index: config.get('esConfig.ES_INDEX_JOB_CANDIDATE'),
id: data.id
})
await esClient.updateExtra({
index: config.get('esConfig.ES_INDEX_JOB_CANDIDATE'),
id: data.id,
Expand All @@ -124,7 +130,8 @@ async function processUpdate (message, transactionId) {
})
await postMessageToZapier({
type: constants.Zapier.MessageType.JobCandidateUpdate,
payload: data
payload: data,
previousData
})
}

Expand Down
Loading