Skip to content

Commit

Permalink
Merge branch 'master' into update-kue
Browse files Browse the repository at this point in the history
  • Loading branch information
iamigo committed Jun 19, 2017
2 parents ac2576f + 73be328 commit 89a4bd1
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .dockerignore
@@ -0,0 +1,4 @@
.dockerignore
Dockerfile
docker-compose.yml
.git
19 changes: 19 additions & 0 deletions Dockerfile
@@ -0,0 +1,19 @@
FROM node:6.10.3

RUN useradd -U -d /opt/refocus refocus
ENV HOME=/opt/refocus
COPY . $HOME
RUN chown -R refocus:refocus $HOME

USER refocus
WORKDIR $HOME
RUN npm install

# sleep is to support pause during startup for deploys in kubernetes - delays start of refocus container to let pg and redis containers to start within the same pod.
ENV SLEEP=0
ENV PGHOST=pg
ENV REDIS_URL=//redis:6379

EXPOSE 3000

CMD [ "/bin/sh", "-c", "sleep $SLEEP; npm start" ]
4 changes: 4 additions & 0 deletions config/toggles.js
Expand Up @@ -89,6 +89,10 @@ const longTermToggles = {
enforceWritePermission:
environmentVariableTrue(pe, 'ENFORCE_WRITE_PERMISSION'),

// Add some instrumentation for real time events
instrumentRealtimeEvents:
environmentVariableTrue(pe, 'INSTRUMENT_REALTIME_EVENTS'),

// Enforce that all API requests have valid API token
requireAccessToken: environmentVariableTrue(pe, 'REQUIRE_ACCESS_TOKEN'),

Expand Down
18 changes: 18 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,18 @@
version: '2'
services:
refocus-app:
build: .
ports:
- "3000:3000"
depends_on:
- "redis"
- "pg"
redis:
image: "redis:3.2.8"
expose:
- 6379
pg:
image: "postgres:9.6.2"
expose:
- 5432

1 change: 1 addition & 0 deletions docs/docs/01-quickstart.md
Expand Up @@ -83,6 +83,7 @@ You have two ways to deploy Refocus. Select the one that best meets your needs.

- I want [one-click Heroku deployment](./03-quickstartheroku.html)
- I want to [download and build and deploy locally](./04-quickstartlocal.html)
- I want to [run Refocus locally as docker container](./05-quickstartlocaldocker.html)

Refocus requires that both Redis and PostgreSQL are running. After Refocus is deployed, create an account and sign in.

Expand Down
12 changes: 12 additions & 0 deletions docs/docs/05-quickstartlocaldocker.md
@@ -0,0 +1,12 @@
---
layout: docs
title: Quick Start with Local Docker
---

# QuickStart with Local Docker
# Prerequisites
1. Install docker [docker-for-mac](https://docs.docker.com/docker-for-mac/install/).
# Start refocus with dependencies
1. Clone this git repository.
2. Run `cd refocus`.
3. Run `docker-compose up`
9 changes: 8 additions & 1 deletion realtime/redisPublisher.js
Expand Up @@ -14,6 +14,7 @@
const pub = require('../cache/redisCache').client.pub;
const channelName = require('../config').redis.channelName;
const sampleEvent = require('./constants').events.sample;
const featureToggles = require('feature-toggles');

/**
* When passed an sample object, either a sequelize sample object or
Expand Down Expand Up @@ -81,7 +82,13 @@ function publishObject(inst, event, changedKeys, ignoreAttributes) {
}

if (obj[event]) {
return pub.publish(channelName.toString(), JSON.stringify(obj));
const objectAsString = JSON.stringify(obj);
if (featureToggles.isFeatureEnabled('instrumentRealtimeEvents')) {
console.log(`[RT] publishTimestamp=${(new Date()).toISOString()} ` +
`size=${objectAsString.length}`);
}

return pub.publish(channelName, objectAsString);
}

return obj;
Expand Down
6 changes: 6 additions & 0 deletions realtime/redisSubscriber.js
Expand Up @@ -12,6 +12,7 @@
'use strict'; // eslint-disable-line strict
const emitter = require('./socketIOEmitter');
const sub = require('../cache/redisCache').client.sub;
const featureToggles = require('feature-toggles');

/**
* Redis subscriber uses socket.io to broadcast.
Expand All @@ -21,6 +22,11 @@ const sub = require('../cache/redisCache').client.sub;
*/
module.exports = (io) => {
sub.on('message', (channel, mssgStr) => {
if (featureToggles.isFeatureEnabled('instrumentRealtimeEvents')) {
console.log(`[RT] subscribeTimestamp=${(new Date()).toISOString()} ` +
`size=${mssgStr.length}`);
}

// message object to be sent to the clients
const mssgObj = JSON.parse(mssgStr);
const key = Object.keys(mssgObj)[0];
Expand Down
5 changes: 5 additions & 0 deletions realtime/socketIOEmitter.js
Expand Up @@ -14,6 +14,7 @@

const rtUtils = require('./utils');
const initEvent = 'refocus.internal.realtime.perspective.namespace.initialize';
const featureToggles = require('feature-toggles');

module.exports = (io, key, mssgObj) => {
const obj = rtUtils.parseObject(mssgObj[key], key);
Expand All @@ -28,6 +29,10 @@ module.exports = (io, key, mssgObj) => {
if (nsp && rtUtils.shouldIEmitThisObj(nsp, obj)) {
// newObjectAsString contains { key: {new: obj }}
io.of(nsp).emit(key, newObjectAsString);

if (featureToggles.isFeatureEnabled('instrumentRealtimeEvents')) {
console.log(`[RT] namespace=${nsp} bytes=${newObjectAsString.length}`);
}
}
}
};

0 comments on commit 89a4bd1

Please sign in to comment.