From f646e94cfae962d5bb744fb1c6671281c83e40cc Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Fri, 21 Apr 2017 15:46:41 +0530 Subject: [PATCH] Reverted docker base image to node Moving schedule logic to node via node-cron module --- consumer/Dockerfile | 15 ++++++--------- consumer/package.json | 1 + consumer/src/scheduled-worker.js | 8 ++++---- consumer/src/worker.js | 8 +++++++- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/consumer/Dockerfile b/consumer/Dockerfile index 63ffacc..a2c1d26 100644 --- a/consumer/Dockerfile +++ b/consumer/Dockerfile @@ -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 @@ -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 diff --git a/consumer/package.json b/consumer/package.json index f3fa793..64c3dc3 100644 --- a/consumer/package.json +++ b/consumer/package.json @@ -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" diff --git a/consumer/src/scheduled-worker.js b/consumer/src/scheduled-worker.js index cd0259d..b82d6eb 100644 --- a/consumer/src/scheduled-worker.js +++ b/consumer/src/scheduled-worker.js @@ -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`); @@ -149,7 +149,7 @@ async function start() { }) } else { counter++; - debug('Processed message'); + debug('Processed Empty message'); if (counter >= FETCH_LIMIT) { close(); } @@ -166,5 +166,5 @@ async function start() { } if (!module.parent) { - start(); + start(); } diff --git a/consumer/src/worker.js b/consumer/src/worker.js index 6b9c122..959465c 100644 --- a/consumer/src/worker.js +++ b/consumer/src/worker.js @@ -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'); @@ -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(); @@ -122,4 +124,8 @@ async function start() { if (!module.parent) { start(); + + cron.schedule('*/1 * * * *', function(){ + scheduleStart(); + }); }