Last active
December 15, 2015 20:19
-
-
Save whoeverest/5318148 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffmpeg = require 'fluent-ffmpeg' | |
mongoose = require 'mongoose' | |
amqp = require 'amqp' | |
async = require 'async' | |
# Connect to RabbitMQ | |
amqpConnect = (done) -> | |
# reconnects set to `false` because it called the callback | |
# more then once, raising an exception | |
amqpConnection = amqp.createConnection {host: 'localhost'}, {reconnect: false} | |
amqpConnection.on 'ready', done.bind(this, null, amqpConnection) | |
amqpConnection.on 'error', done.bind(this, "[ ] Error connecting to RabbitMQ") | |
# Connect to Mongo | |
mongoConnect = (done) -> | |
mongoose.connection.on 'open', done.bind(this, null, mongoose) | |
mongoose.connection.on 'error', done.bind(this, "[ ] Error connecting to Mongo") | |
mongoose.connect 'mongodb://localhost/transcodify' | |
# Wait for connections, if completed donefully, continue | |
async.parallel [amqpConnect, mongoConnect], (err, res) -> | |
if err | |
console.log err | |
return # Could not connect to Mongo or RabbitMQ server | |
console.log '[*] Connected to amqp' | |
console.log '[*] Connected to Mongo' | |
console.log res | |
amqpConn = res.amqp | |
mongooseDone = res.mongo | |
amqpConn.queue 'my-queue', (q) -> | |
q.bind 'transcode.start' | |
q.subscribe (message) -> | |
console.log message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment