diff --git a/.circleci/config.yml b/.circleci/config.yml index 451867c5..0be8e121 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -152,7 +152,7 @@ workflows: - UnitTests filters: branches: - only: ['develop'] + only: ['develop', 'connect-performance-testing'] - deployProd: context : org-global requires: diff --git a/src/events/projects/index.js b/src/events/projects/index.js index cc109d6b..07c91986 100644 --- a/src/events/projects/index.js +++ b/src/events/projects/index.js @@ -6,7 +6,6 @@ import Joi from 'joi'; import Promise from 'bluebird'; import config from 'config'; import axios from 'axios'; -import moment from 'moment'; import util from '../../util'; import models from '../../models'; import { createPhaseTopic } from '../projectPhases'; @@ -175,7 +174,6 @@ async function projectCreatedKafkaHandler(app, topic, payload) { if (result.error) { throw new Error(result.error); } - const project = payload; if (project.phases && project.phases.length > 0) { @@ -187,46 +185,41 @@ async function projectCreatedKafkaHandler(app, topic, payload) { await Promise.all(topicPromises); app.logger.debug('Topics for phases are successfully created.'); } - // TODO: temporary disable this feature, until we release TaaS APP - if (false === true && project.type === 'talent-as-a-service') { - const specialists = _.get(project, 'details.taasDefinition.specialists'); - if (!specialists || !specialists.length) { - app.logger.debug(`no specialists found in the project ${project.id}`); - return; + try { + if (project.type === 'talent-as-a-service') { + const jobs = _.get(project, 'details.taasDefinition.taasJobs'); + if (!jobs || !jobs.length) { + app.logger.debug(`no jobs found in the project id: ${project.id}`); + return; + } + app.logger.debug(`${jobs.length} jobs found in the project id: ${project.id}`); + await Promise.all( + _.map( + jobs, + (job) => { + // make sure that skills would be unique in the list and only include ones with 'skillId' (actually they all suppose to be with skillId) + const skills = _.chain(job.skills).map('skillId').uniq().compact() + .value(); + return createTaasJob({ + projectId: project.id, + title: job.title, + description: job.description, + skills, + numPositions: Number(job.people), + resourceType: _.get(job, 'role.value', ''), + rateType: 'weekly', // hardcode for now + workload: _.get(job, 'workLoad.title', '').toLowerCase(), + }).then((createdJob) => { + app.logger.debug(`jobId: ${createdJob.id} job created with title "${createdJob.title}"`); + }).catch((err) => { + app.logger.error(`Unable to create job with title "${job.title}": ${err.message}`); + }); + }, + ), + ); } - const targetSpecialists = _.filter(specialists, specialist => Number(specialist.people) > 0); // must be at least one people - await Promise.all( - _.map( - targetSpecialists, - (specialist) => { - const startDate = new Date(); - const endDate = moment(startDate).add(Number(specialist.duration), 'M'); // the unit of duration is month - // make sure that skills would be unique in the list - const skills = _.uniq( - // use both, required and additional skills for jobs - specialist.skills.concat(specialist.additionalSkills) - // only include skills with `skillId` and ignore custom skills in jobs - .filter(skill => skill.skillId).map(skill => skill.skillId), - ); - return createTaasJob({ - projectId: project.id, - externalId: '0', // hardcode for now - description: specialist.roleTitle, - startDate, - endDate, - skills, - numPositions: Number(specialist.people), - resourceType: specialist.role, - rateType: 'hourly', // hardcode for now - workload: _.get(specialist, 'workLoad.title', '').toLowerCase(), - }).then((job) => { - app.logger.debug(`jobId: ${job.id} job created for roleTitle ${specialist.roleTitle}`); - }).catch((err) => { - app.logger.error(`Unable to create job for ${specialist.roleTitle}: ${err.message}`); - }); - }, - ), - ); + } catch (error) { + app.logger.error(`Error while creating TaaS jobs: ${error}`); } }