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
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 6f48369
add backups to gitignore
Lacrymology 3e47558
driver skeleton
Lacrymology 0f2a710
basic requirements and simple methods
Lacrymology 6bfae9e
TEMPORARY db setup
Lacrymology ee390e8
load db collections
Lacrymology 56c3ba4
read playlists from DB function prototype
Lacrymology 51503ec
search scheds that overlap with the timeframe now-config.load_time
Lacrymology ea64ece
find the playlist referenced by the sched in the database, and turn i…
Lacrymology 155bdfa
create the Media and Playlist objects, and call the defined callback
Lacrymology 15ca62e
don't need to pass the list as a parameter
Lacrymology 51fc29b
subscribe to mubsub channel and update playlists
Lacrymology 17cc126
add new requirements
Lacrymology 918007d
add the new driver
Lacrymology 8569a12
use the mongo driver in mosto
Lacrymology 8fcd854
use occurrence id as playlist name (unique)
Lacrymology 8d5c482
make sure _id is an ObjectId before changing it to hex string
Lacrymology 059d532
separate C[R]UD message callbacks
Lacrymology 47cc3fc
move playlist driver choice to config file
Lacrymology da60f64
Merge remote-tracking branch 'origin/master' into Lacrymology/playlis…
Lacrymology 504ba83
add the option to pass config JSON objects to drivers
Lacrymology 2ba9a83
Merge branch 'master' into Lacrymology/playlists/mongo-driver
Lacrymology 47c62c4
remove old method
Lacrymology e2d8d6b
move creation of the timestamps within the interest frame to it's own…
Lacrymology 1506b8e
method to check that a given sched is within valid timeframe
Lacrymology dae2b35
only send create messages within the valid time frame
Lacrymology 5e3ad89
whitespace
Lacrymology 7827219
remove personal log line
Lacrymology File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -6,6 +6,7 @@ lib-cov | ||
*.out | *.out | ||
*.pid | *.pid | ||
*.gz | *.gz | ||
*~ | |||
|
|
||
pids | pids | ||
logs | logs | ||
|
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,3 +1,3 @@ | |||
{ | { | ||
|
"playlist_server": "mongo" | ||
} | } |
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
{ | |||
"load_time": 120 | |||
} |
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
var db; | |||
exports.db = function(config) { | |||
//var conf = require('config').MediaDB; | |||
var conf = { | |||
dbName: "mediadb", | |||
dbHost: "localhost", | |||
dbPort: 27017 | |||
}; | |||
db = require('mongoskin').db(conf.dbHost + ':' + conf.dbPort + '/' + conf.dbName + '?auto_reconnect', {safe:true}); | |||
return db; | |||
} |
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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; | |||
}; |
This file contains 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
This file contains 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
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
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