Skip to content

Commit f646e94

Browse files
author
Vikas Agarwal
committed
Reverted docker base image to node
Moving schedule logic to node via node-cron module
1 parent f04eb92 commit f646e94

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

consumer/Dockerfile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
FROM ubuntu
1+
FROM node:6.9.4
22
LABEL version="1.0"
33
LABEL description="Topcoder Salesforce Integration"
44

5+
RUN apt-get update && \
6+
apt-get upgrade -y
57

6-
7-
RUN apt-get update && apt-get upgrade -y && apt-get install -y cron logrotate curl
8-
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
9-
RUN apt-get install -y nodejs
10-
11-
RUN apt-get install cron -y
8+
#RUN apt-get install cron -y
129

1310

1411
# Create app directory
@@ -22,9 +19,9 @@ RUN npm install
2219

2320
RUN npm install -g forever babel-cli
2421

25-
RUN crontab config/scheduler-cron
22+
#RUN crontab config/scheduler-cron
2623

27-
RUN service cron start
24+
#RUN service cron start
2825

2926
EXPOSE 80
3027

consumer/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"joi": "^9.0.4",
4747
"jsonwebtoken": "^7.1.7",
4848
"lodash": "^4.14.2",
49+
"node-cron": "^1.1.3",
4950
"superagent": "^2.1.0",
5051
"superagent-promise": "^1.1.0",
5152
"winston": "^2.2.0"

consumer/src/scheduled-worker.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ function assertExchangeQueues(channel, exchangeName, queue) {
103103
/**
104104
* Start the worker
105105
*/
106-
async function start() {
106+
export async function start() {
107107
try {
108-
console.log(config.rabbitmqURL);
108+
console.log("Scheduled Worker Connecting to RabbitMQ: " + config.rabbitmqURL.substr(-5));
109109
connection = await amqp.connect(config.rabbitmqURL);
110110
connection.on('error', (e) => {
111111
logger.logFullError(e, `ERROR IN CONNECTION`);
@@ -149,7 +149,7 @@ async function start() {
149149
})
150150
} else {
151151
counter++;
152-
debug('Processed message');
152+
debug('Processed Empty message');
153153
if (counter >= FETCH_LIMIT) {
154154
close();
155155
}
@@ -166,5 +166,5 @@ async function start() {
166166
}
167167

168168
if (!module.parent) {
169-
start();
169+
start();
170170
}

consumer/src/worker.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import _ from 'lodash';
88
import logger from './common/logger';
99
import ConsumerService from './services/ConsumerService';
1010
import { EVENT } from '../config/constants';
11+
import cron from 'node-cron';
12+
import { start as scheduleStart } from './scheduled-worker'
1113

1214
const debug = require('debug')('app:worker');
1315

@@ -102,7 +104,7 @@ export async function consume(channel, exchangeName, queue, publishChannel) {
102104
*/
103105
async function start() {
104106
try {
105-
console.log(config.rabbitmqURL);
107+
console.log("Worker Connecting to RabbitMQ: " + config.rabbitmqURL.substr(-5));
106108
connection = await amqp.connect(config.rabbitmqURL);
107109
debug('created connection successfully with URL: ' + config.rabbitmqURL);
108110
const channel = await connection.createConfirmChannel();
@@ -122,4 +124,8 @@ async function start() {
122124

123125
if (!module.parent) {
124126
start();
127+
128+
cron.schedule('*/1 * * * *', function(){
129+
scheduleStart();
130+
});
125131
}

0 commit comments

Comments
 (0)