Skip to content

Instantly share code, notes, and snippets.

@khacanh
Last active August 29, 2015 14:15
Show Gist options
  • Save khacanh/58b46c673cb720e1d888 to your computer and use it in GitHub Desktop.
Save khacanh/58b46c673cb720e1d888 to your computer and use it in GitHub Desktop.
Queries
// script1.js
// This is our test script
// This simple script will bump the lock to 100%
var Firebase = require('firebase');
var firebase = new Firebase('<FIREBASEROOT>/mychat/presences');
var token = '<FIREBASE_SECRET>';
function cleanup(code) {
console.log("EXIT");
Firebase.goOffline();
process.exit();
}
process.on("SIGINT", cleanup);
firebase.authWithCustomToken(token, function(error, result) {
console.log("Authenticated!!!");
firebase.orderByChild("lastSeen")
.limitToFirst(10)
.on('child_added', function(snapshot) {
console.log(snapshot.key());
});
});
/***********************************************************/
// script2.js
// This is what we do with the worker
// A worker is assigned with a segment to watch over
var segment = {start: '000*', end: '07f~'};
var Firebase = require('firebase');
var firebase = new Firebase('<FIREBASEROOT>/mychat/presences');
var token = '<FIREBASE_SECRET>';
function cleanup(code) {
console.log("EXIT");
Firebase.goOffline();
process.exit();
}
process.on("SIGINT", cleanup);
firebase.authWithCustomToken(token, function(error, result) {
console.log("Authenticated!!!");
firebase.orderByKey()
.startAt(segment.start)
.endAt(segment.end)
.on("child_added", function(snapshot) {
// process the snapshot
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment