Created
August 30, 2016 15:03
-
-
Save akerouanton/0c377872b93e9e88dad390cce2696e81 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const amqp = require('amqp'); | |
const config = require('./config'); | |
const logger = require('./lib/logger'); | |
const Analysis = require('./lib/Analysis'); | |
const Runner = require('./lib/Runner'); | |
const connection = amqp.createConnection(config.amqp); | |
const runner = new Runner(config.docker); | |
connection.on('error', logger.error); | |
connection.on('ready', () => { | |
logger.log('Connection ready.'); | |
connection.queue('analyzer', {'durable': true}, (queue) => { | |
queue.bind('amq.direct', 'run_analysis'); | |
logger.log('Analyser queue declared, binding done.'); | |
queue.subscribe(onMessageReceived); | |
}); | |
}); | |
const onMessageReceived = (message) => { | |
logger.log('New message received.'); | |
try { | |
const analysis = new Analysis( | |
message.build_id, | |
message.project_name, | |
message.project_url, | |
message.analyzer, | |
runner | |
); | |
analysis.run(); | |
} catch (e) { | |
logger.error(e); | |
} | |
}; | |
process.on('SIGTERM', () => { | |
connection.disconnect(); // @TODO: debug this | |
process.exit(0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment