Skip to content

Commit

Permalink
Reverted docker base image to node
Browse files Browse the repository at this point in the history
Moving schedule logic to node via node-cron module
  • Loading branch information
Vikas Agarwal committed Apr 21, 2017
1 parent f04eb92 commit f646e94
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
15 changes: 6 additions & 9 deletions consumer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
FROM ubuntu
FROM node:6.9.4
LABEL version="1.0"
LABEL description="Topcoder Salesforce Integration"

RUN apt-get update && \
apt-get upgrade -y


RUN apt-get update && apt-get upgrade -y && apt-get install -y cron logrotate curl
RUN curl -sL https://deb.nodesource.com/setup_6.x | bash -
RUN apt-get install -y nodejs

RUN apt-get install cron -y
#RUN apt-get install cron -y


# Create app directory
Expand All @@ -22,9 +19,9 @@ RUN npm install

RUN npm install -g forever babel-cli

RUN crontab config/scheduler-cron
#RUN crontab config/scheduler-cron

RUN service cron start
#RUN service cron start

EXPOSE 80

Expand Down
1 change: 1 addition & 0 deletions consumer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"joi": "^9.0.4",
"jsonwebtoken": "^7.1.7",
"lodash": "^4.14.2",
"node-cron": "^1.1.3",
"superagent": "^2.1.0",
"superagent-promise": "^1.1.0",
"winston": "^2.2.0"
Expand Down
8 changes: 4 additions & 4 deletions consumer/src/scheduled-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ function assertExchangeQueues(channel, exchangeName, queue) {
/**
* Start the worker
*/
async function start() {
export async function start() {
try {
console.log(config.rabbitmqURL);
console.log("Scheduled Worker Connecting to RabbitMQ: " + config.rabbitmqURL.substr(-5));
connection = await amqp.connect(config.rabbitmqURL);
connection.on('error', (e) => {
logger.logFullError(e, `ERROR IN CONNECTION`);
Expand Down Expand Up @@ -149,7 +149,7 @@ async function start() {
})
} else {
counter++;
debug('Processed message');
debug('Processed Empty message');
if (counter >= FETCH_LIMIT) {
close();
}
Expand All @@ -166,5 +166,5 @@ async function start() {
}

if (!module.parent) {
start();
start();
}
8 changes: 7 additions & 1 deletion consumer/src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import _ from 'lodash';
import logger from './common/logger';
import ConsumerService from './services/ConsumerService';
import { EVENT } from '../config/constants';
import cron from 'node-cron';
import { start as scheduleStart } from './scheduled-worker'

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

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

if (!module.parent) {
start();

cron.schedule('*/1 * * * *', function(){
scheduleStart();
});
}

0 comments on commit f646e94

Please sign in to comment.