Skip to content

Instantly share code, notes, and snippets.

@whoeverest
Last active December 15, 2015 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save whoeverest/5318148 to your computer and use it in GitHub Desktop.
Save whoeverest/5318148 to your computer and use it in GitHub Desktop.
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