Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 9c33df5

Browse files
committed
feat: updates from another repo
1 parent 6d7ea04 commit 9c33df5

File tree

5 files changed

+47
-19
lines changed

5 files changed

+47
-19
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Microservice to manage CRUD operations for all things Projects.
1313
* Install [libpg](https://www.npmjs.com/package/pg-native)
1414

1515
### Steps to run locally
16-
1716
1. Install node dependencies
1817
```bash
1918
npm install
@@ -142,5 +141,4 @@ You may replace 172.17.0.1 with your docker0 IP.
142141
You can paste **swagger.yaml** to [swagger editor](http://editor.swagger.io/) or import **postman.json** and **postman_environment.json** to verify endpoints.
143142

144143
#### Deploying without docker
145-
146144
If you don't want to use docker to deploy to localhost. You can simply run `npm run start:dev` from root of project. This should start the server on default port `8001`.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
"babel-plugin-add-module-exports": "^0.2.1",
7676
"babel-plugin-transform-runtime": "^6.23.0",
7777
"babel-preset-es2015": "^6.9.0",
78-
"bunyan": "^1.8.1",
78+
"bunyan": "^1.8.12",
7979
"chai": "^3.5.0",
8080
"chai-as-promised": "^7.1.1",
8181
"eslint": "^3.16.1",

src/events/index.js

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,59 @@ import {
1414
milestoneUpdatedKafkaHandler,
1515
} from './milestones';
1616

17+
/**
18+
* Void RabbitMQ event handler.
19+
* It "ack"s messages which are still published but we don't want to consume.
20+
*
21+
* It's used to "disable" events which we don't want to handle anymore. But for a time being
22+
* we don't want to remove the code of them until we validate that we are good without them.
23+
*
24+
* @param {Object} logger logger
25+
* @param {Object} msg RabbitMQ message
26+
* @param {Object} channel RabbitMQ channel
27+
* @returns {Promise} nothing
28+
*/
29+
const voidRabbitHandler = (logger, msg, channel) => {
30+
logger.debug('Calling void RabbitMQ handler.');
31+
channel.ack(msg);
32+
return Promise.resolve();
33+
};
34+
1735
// NOTE: We use "project-processor-es" for ES indexing now.
1836
// So I disable indexing using RabbitMQ for a transition period for most of the objects
1937
// which don't have any special logic.
2038
// As soon as we are sure, that "project-processor-es" works well for ES indexing,
2139
// we should completely remove the handlers for this events.
2240
export const rabbitHandlers = {
2341
'project.initial': projectCreatedHandler, // is only used `seedElasticsearchIndex.js` and can be removed
24-
// [EVENT.ROUTING_KEY.PROJECT_DRAFT_CREATED]: projectCreatedHandler,
25-
// [EVENT.ROUTING_KEY.PROJECT_UPDATED]: projectUpdatedHandler,
26-
// [EVENT.ROUTING_KEY.PROJECT_DELETED]: projectDeletedHandler,
27-
// [EVENT.ROUTING_KEY.PROJECT_MEMBER_ADDED]: projectMemberAddedHandler,
28-
// [EVENT.ROUTING_KEY.PROJECT_MEMBER_REMOVED]: projectMemberRemovedHandler,
29-
// [EVENT.ROUTING_KEY.PROJECT_MEMBER_UPDATED]: projectMemberUpdatedHandler,
30-
// [EVENT.ROUTING_KEY.PROJECT_MEMBER_INVITE_CREATED]: projectMemberInviteCreatedHandler,
31-
// [EVENT.ROUTING_KEY.PROJECT_MEMBER_INVITE_UPDATED]: projectMemberInviteUpdatedHandler,
32-
// [EVENT.ROUTING_KEY.PROJECT_ATTACHMENT_ADDED]: projectAttachmentAddedHandler,
33-
// [EVENT.ROUTING_KEY.PROJECT_ATTACHMENT_REMOVED]: projectAttachmentRemovedHandler,
34-
// [EVENT.ROUTING_KEY.PROJECT_ATTACHMENT_UPDATED]: projectAttachmentUpdatedHandler,
42+
[EVENT.ROUTING_KEY.PROJECT_DRAFT_CREATED]: voidRabbitHandler, // DISABLED
43+
[EVENT.ROUTING_KEY.PROJECT_UPDATED]: voidRabbitHandler, // DISABLED
44+
[EVENT.ROUTING_KEY.PROJECT_DELETED]: voidRabbitHandler, // DISABLED
45+
[EVENT.ROUTING_KEY.PROJECT_MEMBER_ADDED]: voidRabbitHandler, // DISABLED
46+
[EVENT.ROUTING_KEY.PROJECT_MEMBER_REMOVED]: voidRabbitHandler, // DISABLED
47+
[EVENT.ROUTING_KEY.PROJECT_MEMBER_UPDATED]: voidRabbitHandler, // DISABLED
48+
[EVENT.ROUTING_KEY.PROJECT_MEMBER_INVITE_CREATED]: voidRabbitHandler, // DISABLED
49+
[EVENT.ROUTING_KEY.PROJECT_MEMBER_INVITE_UPDATED]: voidRabbitHandler, // DISABLED
50+
[EVENT.ROUTING_KEY.PROJECT_ATTACHMENT_ADDED]: voidRabbitHandler, // DISABLED
51+
[EVENT.ROUTING_KEY.PROJECT_ATTACHMENT_REMOVED]: voidRabbitHandler, // DISABLED
52+
[EVENT.ROUTING_KEY.PROJECT_ATTACHMENT_UPDATED]: voidRabbitHandler, // DISABLED
3553

3654
// project phase handles additionally implement logic for creating associated topics in Message Service
3755
[EVENT.ROUTING_KEY.PROJECT_PHASE_ADDED]: projectPhaseAddedHandler, // index in ES because of cascade updates
3856
[EVENT.ROUTING_KEY.PROJECT_PHASE_REMOVED]: projectPhaseRemovedHandler, // doesn't index in ES
3957
[EVENT.ROUTING_KEY.PROJECT_PHASE_UPDATED]: projectPhaseUpdatedHandler, // index in ES because of cascade updates
4058

59+
[EVENT.ROUTING_KEY.PROJECT_PHASE_PRODUCT_ADDED]: voidRabbitHandler, // DISABLED
60+
[EVENT.ROUTING_KEY.PROJECT_PHASE_PRODUCT_REMOVED]: voidRabbitHandler, // DISABLED
61+
[EVENT.ROUTING_KEY.PROJECT_PHASE_PRODUCT_UPDATED]: voidRabbitHandler, // DISABLED
62+
4163
// Timeline and milestone
4264
'timeline.initial': timelineAddedHandler, // is only used `seedElasticsearchIndex.js` and can be removed
65+
[EVENT.ROUTING_KEY.TIMELINE_ADDED]: voidRabbitHandler, // DISABLED
66+
[EVENT.ROUTING_KEY.TIMELINE_REMOVED]: voidRabbitHandler, // DISABLED
67+
[EVENT.ROUTING_KEY.TIMELINE_UPDATED]: voidRabbitHandler, // DISABLED
4368
[EVENT.ROUTING_KEY.MILESTONE_ADDED]: milestoneAddedHandler, // index in ES because of cascade updates
69+
[EVENT.ROUTING_KEY.MILESTONE_REMOVED]: voidRabbitHandler, // DISABLED
4470
[EVENT.ROUTING_KEY.MILESTONE_UPDATED]: milestoneUpdatedHandler, // index in ES because of cascade updates
4571
};
4672

src/routes/projects/list.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,11 @@ module.exports = [
569569
return retrieveProjects(req, criteria, sort, req.query.fields)
570570
.then((result) => {
571571
if (result.rows.length === 0) {
572+
req.log.debug('No projects found in ES');
572573
return retrieveProjectsFromDB(req, criteria, sort, req.query.fields)
573574
.then(r => util.setPaginationHeaders(req, res, r));
574575
}
576+
req.log.debug('Projects found in ES');
575577
// set header
576578
return util.setPaginationHeaders(req, res, result);
577579
})
@@ -584,9 +586,11 @@ module.exports = [
584586
return retrieveProjects(req, criteria, sort, req.query.fields)
585587
.then((result) => {
586588
if (result.rows.length === 0) {
589+
req.log.debug('No projects found in ES');
587590
return retrieveProjectsFromDB(req, criteria, sort, req.query.fields)
588591
.then(r => util.setPaginationHeaders(req, res, r));
589592
}
593+
req.log.debug('Projects found in ES');
590594
return util.setPaginationHeaders(req, res, result);
591595
})
592596
.catch(err => next(err));

src/services/busApi.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ async function getClient() {
4646
function createEvent(topic, payload, logger) {
4747
logger.debug(`Sending message to topic ${topic}: ${JSON.stringify(payload)}`);
4848
return getClient().then((busClient) => {
49-
logger.debug('calling bus-api');
49+
logger.debug(`calling bus-api for topic ${topic}`);
5050
return busClient.post('/bus/events', {
5151
topic,
5252
originator: 'project-api',
5353
timestamp: (new Date()).toISOString(),
5454
'mime-type': 'application/json',
5555
payload,
5656
}).then((resp) => {
57-
logger.debug('Sent event to bus-api');
58-
logger.debug(`Sent event to bus-api [data]: ${_.get(resp, 'data')}`);
59-
logger.debug(`Sent event to bus-api [status]: ${_.get(resp, 'status')}`);
57+
logger.debug(`Sent event to bus-api for topic ${topic}`);
58+
logger.debug(`Sent event to bus-api for topic ${topic} [data]: ${_.get(resp, 'data')}`);
59+
logger.debug(`Sent event to bus-api for topic ${topic} [status]: ${_.get(resp, 'status')}`);
6060
}).catch((error) => {
61-
logger.debug('Error sending event to bus-api');
61+
logger.debug(`Error sending event to bus-api for topic ${topic}`);
6262
if (error.response) {
6363
// The request was made and the server responded with a status code
6464
// that falls out of the range of 2xx

0 commit comments

Comments
 (0)