Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

playlists/mongo driver #28

Merged
merged 28 commits into from

2 participants

@Lacrymology

Basic functionality in mongo playlists driver

It calls a bunch of Create callback messages with playlists loaded from the database.
it calls Create / Update / Delete callbacks with playlist data from pub/sub messages.

It assumes Update and Delete callbacks ignore unknown playlists

TODO: it still doesn't filter out newly created playlists' pub/sub messages to check if the time-frame is right

Lacrymology added some commits
@Lacrymology Lacrymology add mongo-driver file
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
d975faa
@Lacrymology Lacrymology add backups to gitignore
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
6f48369
@Lacrymology Lacrymology driver skeleton
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
3e47558
@Lacrymology Lacrymology basic requirements and simple methods
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
0f2a710
@Lacrymology Lacrymology TEMPORARY db setup
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
6bfae9e
@Lacrymology Lacrymology load db collections
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
ee390e8
@Lacrymology Lacrymology read playlists from DB function prototype
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
56c3ba4
@Lacrymology Lacrymology search scheds that overlap with the timeframe now-config.load_time 51503ec
@Lacrymology Lacrymology find the playlist referenced by the sched in the database, and turn i…
…t into a Playlist object

Signed-off-by: Tomas Neme <lacrymology@gmail.com>
ea64ece
@Lacrymology Lacrymology create the Media and Playlist objects, and call the defined callback
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
155bdfa
@Lacrymology Lacrymology don't need to pass the list as a parameter
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
15ca62e
@Lacrymology Lacrymology subscribe to mubsub channel and update playlists
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
51fc29b
@Lacrymology Lacrymology add new requirements
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
17cc126
@Lacrymology Lacrymology add the new driver
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
918007d
@Lacrymology Lacrymology use the mongo driver in mosto
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
8569a12
@Lacrymology Lacrymology use occurrence id as playlist name (unique)
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
8fcd854
@Lacrymology Lacrymology make sure _id is an ObjectId before changing it to hex string
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
8d5c482
@Lacrymology Lacrymology separate C[R]UD message callbacks
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
059d532
@Lacrymology Lacrymology move playlist driver choice to config file
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
47cc3fc
@Lacrymology Lacrymology Merge remote-tracking branch 'origin/master' into Lacrymology/playlis…
…ts/mongo-driver
da60f64
@Lacrymology Lacrymology add the option to pass config JSON objects to drivers
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
504ba83
@Lacrymology Lacrymology Merge branch 'master' into Lacrymology/playlists/mongo-driver 2ba9a83
Lacrymology added some commits
@Lacrymology Lacrymology remove old method
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
47c62c4
@Lacrymology Lacrymology move creation of the timestamps within the interest frame to it's own…
… method

Signed-off-by: Tomas Neme <lacrymology@gmail.com>
e2d8d6b
@Lacrymology Lacrymology method to check that a given sched is within valid timeframe
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
1506b8e
@Lacrymology Lacrymology only send create messages within the valid time frame
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
dae2b35
@Lacrymology Lacrymology whitespace
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
5e3ad89
@jmrunge jmrunge commented on the diff
drivers/playlists/db.js
@@ -0,0 +1,11 @@
+var db;
+exports.db = function(config) {
+ //var conf = require('config').MediaDB;
+ var conf = {
@jmrunge Owner
jmrunge added a note

Shouldnt this be on the config file?

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

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

@jmrunge Owner
jmrunge added a note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
drivers/playlists/mongo-driver.js
((15 lines not shown))
+
+ 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);
+ } else {
+ console.log('new sched outside time frame')
@jmrunge Owner
jmrunge added a note

Please follow logging rules:
mbc-mosto: [INFO] Received new sched outside time frame

oops, that line was mine, for debugging.

I didn't do any proper logging because I want to use a real logging facility

@jmrunge Owner
jmrunge added a note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jmrunge
Owner
@Lacrymology Lacrymology remove personal log line
Signed-off-by: Tomas Neme <lacrymology@gmail.com>
7827219
This was referenced
@jmrunge
Owner

Fixes #5 and #11

@jmrunge jmrunge merged commit 509337a into master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 28, 2013
  1. @Lacrymology

    add mongo-driver file

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  2. @Lacrymology

    add backups to gitignore

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  3. @Lacrymology

    driver skeleton

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  4. @Lacrymology

    basic requirements and simple methods

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  5. @Lacrymology

    TEMPORARY db setup

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  6. @Lacrymology

    load db collections

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  7. @Lacrymology

    read playlists from DB function prototype

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  8. @Lacrymology
  9. @Lacrymology

    find the playlist referenced by the sched in the database, and turn i…

    Lacrymology authored
    …t into a Playlist object
    
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  10. @Lacrymology

    create the Media and Playlist objects, and call the defined callback

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  11. @Lacrymology

    don't need to pass the list as a parameter

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  12. @Lacrymology

    subscribe to mubsub channel and update playlists

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  13. @Lacrymology

    add new requirements

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  14. @Lacrymology

    add the new driver

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  15. @Lacrymology

    use the mongo driver in mosto

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  16. @Lacrymology

    use occurrence id as playlist name (unique)

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
Commits on Apr 3, 2013
  1. @Lacrymology

    make sure _id is an ObjectId before changing it to hex string

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  2. @Lacrymology

    separate C[R]UD message callbacks

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  3. @Lacrymology

    move playlist driver choice to config file

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  4. @Lacrymology
Commits on Apr 5, 2013
  1. @Lacrymology

    add the option to pass config JSON objects to drivers

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  2. @Lacrymology
  3. @Lacrymology

    remove old method

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  4. @Lacrymology

    move creation of the timestamps within the interest frame to it's own…

    Lacrymology authored
    … method
    
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  5. @Lacrymology

    method to check that a given sched is within valid timeframe

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  6. @Lacrymology

    only send create messages within the valid time frame

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
  7. @Lacrymology

    whitespace

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
Commits on Apr 6, 2013
  1. @Lacrymology

    remove personal log line

    Lacrymology authored
    Signed-off-by: Tomas Neme <lacrymology@gmail.com>
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -6,6 +6,7 @@ lib-cov
*.out
*.pid
*.gz
+*~
pids
logs
View
2  config.json
@@ -1,3 +1,3 @@
{
-
+ "playlist_server": "mongo"
}
View
3  drivers/playlists/conf/mongo-driver.json
@@ -0,0 +1,3 @@
+{
+ "load_time": 120
+}
View
11 drivers/playlists/db.js
@@ -0,0 +1,11 @@
+var db;
+exports.db = function(config) {
+ //var conf = require('config').MediaDB;
+ var conf = {
@jmrunge Owner
jmrunge added a note

Shouldnt this be on the config file?

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

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

@jmrunge Owner
jmrunge added a note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ dbName: "mediadb",
+ dbHost: "localhost",
+ dbPort: 27017
+ };
+ db = require('mongoskin').db(conf.dbHost + ':' + conf.dbPort + '/' + conf.dbName + '?auto_reconnect', {safe:true});
+ return db;
+}
View
114 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;
+};
View
13 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;
this.driver = undefined;
@@ -11,7 +12,9 @@ function playlists_driver(type) {
console.log("mbc-mosto: [INFO] Creating playlists driver for type [" + type + "]");
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 {
var err = new Error("mbc-mosto: [ERROR] Unknown type of driver [" + type + "]");
console.error(err);
@@ -47,7 +50,7 @@ function playlists_driver(type) {
}
-exports = module.exports = function(type) {
- var driver = new playlists_driver(type);
+exports = module.exports = function(type, config) {
+ var driver = new playlists_driver(type, config);
return driver;
};
View
5 mosto.js
@@ -142,8 +142,6 @@ function mosto(configFile) {
this.configFile = configFile;
this.config = false;
this.playlists = [];
- this.server = new mvcp_server("melted");
- this.driver = new playlists_driver("json");
if (!this.configFile)
this.configFile = './config.json';
@@ -151,6 +149,9 @@ function mosto(configFile) {
console.log("mbc-mosto: [INFO] Reading configuration from " + 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... ") ;
View
5 package.json
@@ -23,7 +23,10 @@
"underscore" : "1.2.x",
"node-uuid" : "1.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": {
"mocha" : "1.7.x"
Something went wrong with that request. Please try again.