Skip to content

Commit

Permalink
Fail!
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeiri committed Nov 14, 2016
1 parent 3a06376 commit 40870b2
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 100 deletions.
16 changes: 9 additions & 7 deletions codefresh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ steps:



push-to-registry:
type: push
#candidate: the image from the build step
candidate: ${{build-step}}
tag: ${{CF_BRANCH}}


integration-tests-step:
type: composition
Expand All @@ -33,4 +27,12 @@ steps:
command: ./tests.sh
composition-variables:
- VOTING_OPTION_A=Trump
- VOTING_OPTION_B=Clinton
- VOTING_OPTION_B=Clinton



push-to-registry:
type: push
#candidate: the image from the build step
candidate: ${{build-step}}
tag: ${{CF_BRANCH}}
186 changes: 93 additions & 93 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,93 +1,93 @@
var express = require('express'),
async = require('async'),
pg = require("pg"),
cookieParser = require('cookie-parser'),
bodyParser = require('body-parser'),
methodOverride = require('method-override'),
app = express(),
server = require('http').Server(app),
io = require('socket.io')(server);

io.set('transports', ['polling']);

var port = process.env.PORT || 4000;
var options = {
optionA : process.env.OPTION_A || "Cats",
optionB : process.env.OPTION_B || "Dogs"
};

io.sockets.on('connection', function (socket) {

socket.emit('message', { text : 'Welcome!' , options: options});

socket.on('subscribe', function (data) {
socket.join(data.channel);
});
});

async.retry(
{times: 1000, interval: 1000},
function(callback) {
pg.connect('postgres://postgres@db/postgres', function(err, client, done) {
if (err) {
console.error("Waiting for db");
}
callback(err, client);
});
},
function(err, client) {
if (err) {
return console.err("Giving up");
}
console.log("Connected to db");
getVotes(client);
}
);


function getVotes(client) {
client.query('SELECT vote, COUNT(id) AS count FROM votes GROUP BY vote', [], function(err, result) {
if (err) {
console.error("Error performing query: " + err);
} else {
var votes = collectVotesFromResult(result);
io.sockets.emit("scores", JSON.stringify(votes));
}

setTimeout(function() {getVotes(client) }, 1000);
});
}



function collectVotesFromResult(result) {
var votes = {a: 0, b: 0};

result.rows.forEach(function (row) {
votes[row.vote] = parseInt(row.count);
});

return votes;
}

app.use(cookieParser());
app.use(bodyParser());
app.use(methodOverride('X-HTTP-Method-Override'));
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
next();
});

app.use(express.static(__dirname + '/views'));

app.get('/', function (req, res) {
res.sendFile(path.resolve(__dirname + '/views/index.html'));
});


server.listen(port, function () {
var port = server.address().port;
console.log('App running on port ' + port);
});
// var express = require('express'),
// async = require('async'),
// pg = require("pg"),
// cookieParser = require('cookie-parser'),
// bodyParser = require('body-parser'),
// methodOverride = require('method-override'),
// app = express(),
// server = require('http').Server(app),
// io = require('socket.io')(server);
//
// io.set('transports', ['polling']);
//
// var port = process.env.PORT || 4000;
// var options = {
// optionA : process.env.OPTION_A || "Cats",
// optionB : process.env.OPTION_B || "Dogs"
// };
//
// io.sockets.on('connection', function (socket) {
//
// socket.emit('message', { text : 'Welcome!' , options: options});
//
// socket.on('subscribe', function (data) {
// socket.join(data.channel);
// });
// });
//
// async.retry(
// {times: 1000, interval: 1000},
// function(callback) {
// pg.connect('postgres://postgres@db/postgres', function(err, client, done) {
// if (err) {
// console.error("Waiting for db");
// }
// callback(err, client);
// });
// },
// function(err, client) {
// if (err) {
// return console.err("Giving up");
// }
// console.log("Connected to db");
// getVotes(client);
// }
// );
//
//
// function getVotes(client) {
// client.query('SELECT vote, COUNT(id) AS count FROM votes GROUP BY vote', [], function(err, result) {
// if (err) {
// console.error("Error performing query: " + err);
// } else {
// var votes = collectVotesFromResult(result);
// io.sockets.emit("scores", JSON.stringify(votes));
// }
//
// setTimeout(function() {getVotes(client) }, 1000);
// });
// }
//
//
//
// function collectVotesFromResult(result) {
// var votes = {a: 0, b: 0};
//
// result.rows.forEach(function (row) {
// votes[row.vote] = parseInt(row.count);
// });
//
// return votes;
// }
//
// app.use(cookieParser());
// app.use(bodyParser());
// app.use(methodOverride('X-HTTP-Method-Override'));
// app.use(function(req, res, next) {
// res.header("Access-Control-Allow-Origin", "*");
// res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
// res.header("Access-Control-Allow-Methods", "PUT, GET, POST, DELETE, OPTIONS");
// next();
// });
//
// app.use(express.static(__dirname + '/views'));
//
// app.get('/', function (req, res) {
// res.sendFile(path.resolve(__dirname + '/views/index.html'));
// });
//
//
// server.listen(port, function () {
// var port = server.address().port;
// console.log('App running on port ' + port);
// });

0 comments on commit 40870b2

Please sign in to comment.