Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

playlists/mongo driver #28

Merged
merged 28 commits into from Apr 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d975faa
add mongo-driver file
Lacrymology Mar 28, 2013
6f48369
add backups to gitignore
Lacrymology Mar 28, 2013
3e47558
driver skeleton
Lacrymology Mar 28, 2013
0f2a710
basic requirements and simple methods
Lacrymology Mar 28, 2013
6bfae9e
TEMPORARY db setup
Lacrymology Mar 28, 2013
ee390e8
load db collections
Lacrymology Mar 28, 2013
56c3ba4
read playlists from DB function prototype
Lacrymology Mar 28, 2013
51503ec
search scheds that overlap with the timeframe now-config.load_time
Lacrymology Mar 28, 2013
ea64ece
find the playlist referenced by the sched in the database, and turn i…
Lacrymology Mar 28, 2013
155bdfa
create the Media and Playlist objects, and call the defined callback
Lacrymology Mar 28, 2013
15ca62e
don't need to pass the list as a parameter
Lacrymology Mar 28, 2013
51fc29b
subscribe to mubsub channel and update playlists
Lacrymology Mar 28, 2013
17cc126
add new requirements
Lacrymology Mar 28, 2013
918007d
add the new driver
Lacrymology Mar 28, 2013
8569a12
use the mongo driver in mosto
Lacrymology Mar 28, 2013
8fcd854
use occurrence id as playlist name (unique)
Lacrymology Mar 28, 2013
8d5c482
make sure _id is an ObjectId before changing it to hex string
Lacrymology Apr 3, 2013
059d532
separate C[R]UD message callbacks
Lacrymology Apr 3, 2013
47cc3fc
move playlist driver choice to config file
Lacrymology Apr 3, 2013
da60f64
Merge remote-tracking branch 'origin/master' into Lacrymology/playlis…
Lacrymology Apr 3, 2013
504ba83
add the option to pass config JSON objects to drivers
Lacrymology Apr 5, 2013
2ba9a83
Merge branch 'master' into Lacrymology/playlists/mongo-driver
Lacrymology Apr 5, 2013
47c62c4
remove old method
Lacrymology Apr 5, 2013
e2d8d6b
move creation of the timestamps within the interest frame to it's own…
Lacrymology Apr 5, 2013
1506b8e
method to check that a given sched is within valid timeframe
Lacrymology Apr 5, 2013
dae2b35
only send create messages within the valid time frame
Lacrymology Apr 5, 2013
5e3ad89
whitespace
Lacrymology Apr 5, 2013
7827219
remove personal log line
Lacrymology Apr 6, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,6 +6,7 @@ lib-cov
*.out *.out
*.pid *.pid
*.gz *.gz
*~


pids pids
logs logs
Expand Down
2 changes: 1 addition & 1 deletion config.json
@@ -1,3 +1,3 @@
{ {

"playlist_server": "mongo"
} }
3 changes: 3 additions & 0 deletions drivers/playlists/conf/mongo-driver.json
@@ -0,0 +1,3 @@
{
"load_time": 120
}
11 changes: 11 additions & 0 deletions drivers/playlists/db.js
@@ -0,0 +1,11 @@
var db;
exports.db = function(config) {
//var conf = require('config').MediaDB;
var conf = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldnt this be on the config file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is gone on a later commit, to mbc-common

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That being said, I don't know, I used the 'db' file as it is defined in caspa. The answer is probably yes, there probably shouldn't be any defaults, and the conf file for development should provide it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, please do it.

Enviado desde mi BlackBerry

-----Original Message-----
From: Tomas Neme notifications@github.com
Date: Fri, 05 Apr 2013 17:56:01
To: inaes-tic/mbc-mostombc-mosto@noreply.github.com
Reply-To: inaes-tic/mbc-mosto reply@reply.github.com
Cc: Juan Martin Rungejmrunge@gmail.com
Subject: Re: [mbc-mosto] playlists/mongo driver (#28)

@@ -0,0 +1,11 @@
+var db;
+exports.db = function(config) {

  • //var conf = require('config').MediaDB;
  • var conf = {

That being said, I don't know, I used the 'db' file as it is defined in caspa. The answer is probably yes, there probably shouldn't be any defaults, and the conf file for development should provide it


Reply to this email directly or view it on GitHub:
https://github.com/inaes-tic/mbc-mosto/pull/28/files#r3682848

dbName: "mediadb",
dbHost: "localhost",
dbPort: 27017
};
db = require('mongoskin').db(conf.dbHost + ':' + conf.dbPort + '/' + conf.dbName + '?auto_reconnect', {safe:true});
return db;
}
114 changes: 114 additions & 0 deletions drivers/playlists/mongo-driver.js
@@ -0,0 +1,114 @@
var config = require("./conf/mongo-driver"),
Playlist = require('../../api/Playlist'),
Media = require('../../api/Media'),
mubsub = require("mubsub"),
moment = require("moment");

function mongo_driver() {
var self = this;

this.newPlaylistCallback = undefined;
this.updatePlaylistCallback = undefined;
this.removePlaylistCallback = undefined;

console.log("mbc-mosto: [INFO] Creating mongodb playlists driver");

mongo_driver.prototype.start = function(config) {
var db = require('./db').db(config && config.db);
var client = mubsub(db);

var channel = client.channel('messages', { size: 10000000, max: 5000 });

self.scheds = db.collection('scheds');
self.lists = db.collection('lists');
self.readPlaylists();

channel.subscribe({channel: 'schedbackend', method: 'create'}, function(msg) {
if( self.inTime(msg.model) ) {
self.createPlaylist(msg.model, self.newPlaylistCallback);
}
});
channel.subscribe({channel: 'schedbackend', method: 'update'}, function(msg) {
self.createPlaylist(msg.model, self.updatePlaylistCallback);
});
channel.subscribe({channel: 'schedbackend', method: 'delete'}, function(msg) {
self.deletePlaylistCallback(msg.model._id);
});
};

mongo_driver.prototype.registerNewPlaylistListener = function(newPlaylistCallback) {
self.newPlaylistCallback = newPlaylistCallback;
};
mongo_driver.prototype.registerUpdatePlaylistListener = function(updatePlaylistCallback) {
self.updatePlaylistCallback = updatePlaylistCallback;
};
mongo_driver.prototype.registerRemovePlaylistListener = function(removePlaylistCallback) {
self.removePlaylistCallback = removePlaylistCallback;
};

mongo_driver.prototype.validTimes = function() {
var now = moment(new Date());
var until = moment(new Date());
until.add(config.load_time * 60 * 1000);
return {
from: now,
to: until
}
};

mongo_driver.prototype.inTime = function(sched) {
var boundaries = self.validTimes();
return (sched.start <= boundaries.to.unix() &&
sched.end >= boundaries.from.unix());
};

mongo_driver.prototype.readPlaylists = function() {
// read playlists from the database

/*
* This should get the database's 'scheds' and 'lists' collections
* and turn them into a mosto.api.Playlist
*/
//console.log("mbc-mosto: [INFO] Start reading playlists from " + config.playlists.to_read);
var boundaries = self.validTimes();
var now = boundaries.from;
var until = boundaries.to;
self.scheds.findEach({
start: { $lte: until.unix()},
end: { $gte: now.unix() }}, function(err, sched) {
if( err ) {
console.log(err);
} else if( sched ) {
console.log("Processing sched:", sched);
self.createPlaylist(sched, self.newPlaylistCallback);
} else {
console.log('Done');
}
});
};

mongo_driver.prototype.createPlaylist = function(sched, callback) {
self.lists.findById(sched.list, function(err, list) {
console.log("Processing list:", list);
var startDate = new Date(sched.start * 1000);
var endDate = new Date(sched.end * 1000);
var name = (sched._id.toHexString && sched._id.toHexString()) || sched._id;

var medias = [];
list.models.forEach(function(block) {
// TODO: don't know what goes in type
var type = "default";
var file = block.file;
var length = block.durationraw;
var fps = block.fps;
medias.push(new Media(type, file, length, parseFloat(fps)));
});
callback(new Playlist(name, startDate, medias, endDate));
});
};
}

exports = module.exports = function() {
var driver = new mongo_driver();
return driver;
};
13 changes: 8 additions & 5 deletions drivers/playlists/playlists-driver.js
@@ -1,6 +1,7 @@
var json_driver = require("./json-driver"); var json_driver = require("./json-driver"),
mongo_driver = require("./mongo-driver");


function playlists_driver(type) { function playlists_driver(type, config) {
var self = this; var self = this;


this.driver = undefined; this.driver = undefined;
Expand All @@ -11,7 +12,9 @@ function playlists_driver(type) {
console.log("mbc-mosto: [INFO] Creating playlists driver for type [" + type + "]"); console.log("mbc-mosto: [INFO] Creating playlists driver for type [" + type + "]");


if (type === 'json') { if (type === 'json') {
this.driver = new json_driver(); this.driver = new json_driver(config);
} else if (type === 'mongo') {
this.driver = new mongo_driver(config);
} else { } else {
var err = new Error("mbc-mosto: [ERROR] Unknown type of driver [" + type + "]"); var err = new Error("mbc-mosto: [ERROR] Unknown type of driver [" + type + "]");
console.error(err); console.error(err);
Expand Down Expand Up @@ -47,7 +50,7 @@ function playlists_driver(type) {


} }


exports = module.exports = function(type) { exports = module.exports = function(type, config) {
var driver = new playlists_driver(type); var driver = new playlists_driver(type, config);
return driver; return driver;
}; };
5 changes: 3 additions & 2 deletions mosto.js
Expand Up @@ -142,15 +142,16 @@ function mosto(configFile) {
this.configFile = configFile; this.configFile = configFile;
this.config = false; this.config = false;
this.playlists = []; this.playlists = [];
this.server = new mvcp_server("melted");
this.driver = new playlists_driver("json");


if (!this.configFile) if (!this.configFile)
this.configFile = './config.json'; this.configFile = './config.json';


console.log("mbc-mosto: [INFO] Reading configuration from " + this.configFile); console.log("mbc-mosto: [INFO] Reading configuration from " + this.configFile);


this.config = require(this.configFile); this.config = require(this.configFile);

this.server = new mvcp_server("melted");
this.driver = new playlists_driver(this.config.playlist_server);


console.log("mbc-mosto: [INFO] Starting mbc-mosto... ") ; console.log("mbc-mosto: [INFO] Starting mbc-mosto... ") ;


Expand Down
5 changes: 4 additions & 1 deletion package.json
Expand Up @@ -23,7 +23,10 @@
"underscore" : "1.2.x", "underscore" : "1.2.x",
"node-uuid" : "1.3.x", "node-uuid" : "1.3.x",
"xmlbuilder" : "0.3.x", "xmlbuilder" : "0.3.x",
"watchr" : ">=2.3" "watchr" : ">=2.3",
"mubsub" : "git://github.com/inaes-tic/mubsub.git",
"moment" : "2.0.0",
"mongoskin" : "0.4.x"
}, },
"devDependencies": { "devDependencies": {
"mocha" : "1.7.x" "mocha" : "1.7.x"
Expand Down