diff --git a/.gitignore b/.gitignore index 4cd9e26d8..b3a88b97f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store node_modules storage/a-1.sqlite +.env diff --git a/Procfile b/Procfile new file mode 100644 index 000000000..4487bbcab --- /dev/null +++ b/Procfile @@ -0,0 +1,2 @@ +web: node api/app.js +worker: node sync/app.js diff --git a/api/routes/delta.js b/api/routes/delta.js index 428665fdf..36f6cccf2 100644 --- a/api/routes/delta.js +++ b/api/routes/delta.js @@ -12,17 +12,17 @@ module.exports = (server) => { handler: (request, reply) => { const outputStream = require('stream').Readable(); outputStream._read = () => { return }; - const pushMsg = (msg = "\n") => outputStream.push(msg); + const sendMsg = (msg = "\n") => outputStream.push(msg); request.getAccountDatabase() .then((db) => { return db.Transaction.findAll(findParams(request.query)) .then((transactions = []) => { - transactions.map(JSON.stringify).forEach(pushMsg); - DeltaStreamQueue.subscribe(db.accountId, pushMsg) + transactions.map(JSON.stringify).forEach(sendMsg); + DeltaStreamQueue.subscribe(db.accountId, sendMsg) }) }).then(() => { - const keepAlive = setInterval(pushMsg, 1000); + const keepAlive = setInterval(sendMsg, 1000); request.on("disconnect", () => { clearTimeout(keepAlive) }) return reply(outputStream) }) diff --git a/core/delta-stream-queue.js b/core/delta-stream-queue.js index c1a0f87d9..7caf31972 100644 --- a/core/delta-stream-queue.js +++ b/core/delta-stream-queue.js @@ -5,7 +5,7 @@ bluebird.promisifyAll(redis.Multi.prototype); class DeltaStreamQueue { setup() { - this.client = redis.createClient(); + this.client = redis.createClient(process.env.REDIS_URL); this.client.on("error", console.error); this.client.on("ready", () => console.log("Redis ready")); } diff --git a/package.json b/package.json new file mode 100644 index 000000000..9fbcd1b51 --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "k2", + "version": "0.0.1", + "description": "Sync Engine ++", + "main": "", + "dependencies": {}, + "devDependencies": {}, + "scripts": { + "start": "heroku local", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "dependencies": { + "imap-experiment": "./sync", + "api": "./api" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/nylas/K2.git" + }, + "author": "", + "license": "ISC", + "bugs": { + "url": "https://github.com/nylas/K2/issues" + }, + "homepage": "https://github.com/nylas/K2#readme", + "engines": { + "node": "6.2.2", + "npm": "3.9.5" + } +} diff --git a/sync/package.json b/sync/package.json index 2524ddb1c..320f03fc8 100644 --- a/sync/package.json +++ b/sync/package.json @@ -12,7 +12,6 @@ }, "devDependencies": {}, "scripts": { - "postinstall": "brew install redis", "start": "node app.js", "test": "echo \"Error: no test specified\" && exit 1" },