Permalink
Browse files

[copyright] Updated to 2013

[codestyle] Fixed codestyle
[tests] Updated the tests to chai + latest mocha
  • Loading branch information...
3rd-Eden committed Jan 2, 2013
1 parent 3c25b11 commit 7332a3ab90d5ac45994d461b82a8f72f49509759
Showing with 128 additions and 156 deletions.
  1. +1 −1 LICENSE
  2. +0 −11 index.js
  3. +42 −55 lib/kju.js
  4. +6 −6 package.json
  5. +76 −82 tests/kju.test.js
  6. +3 −1 tests/simulate.death.js
View
@@ -1,4 +1,4 @@
-Copyright (c) 2011 Observer (http://observer.no.de) <info@3rd-Eden.com>
+Copyright (c) 2013 Observe.it (http://observe.it) <opensource@observe.it>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
View
@@ -1,11 +0,0 @@
-/**!
- * kju
- * @copyright (c) 2011 Observer (observer.no.de) <info@3rd-Eden.com>
- * MIT Licensed
- */
-
-/**
- * Require the core module
- */
-
-module.exports = require('./lib/kju');
View
@@ -1,15 +1,15 @@
+'use strict';
+
/**!
* kju
- * @copyright (c) 2011 Observer (observer.no.de) <info@3rd-Eden.com>
+ * @copyright (c) 2013 Observe.it (http://observe.it) <opensource@observe.it>
* MIT Licensed
*/
/**
* Module dependencies
*/
-
var EventEmitter2 = require('eventemitter2').EventEmitter2
- , path = require('path')
, fs = require('fs');
/**
@@ -37,8 +37,7 @@ var EventEmitter2 = require('eventemitter2').EventEmitter2
* @param {Object} configuration kju configuration
* @api public
*/
-
-function kju (configuration) {
+function KJU(configuration) {
var self = this
, option;
@@ -54,7 +53,7 @@ function kju (configuration) {
this.name = 'node_kju_backup.{sequence}.kju';
// apply the configuration
- for (var option in configuration)
+ for (option in configuration)
this[option] = configuration[option];
// these values should not be configured
@@ -75,7 +74,7 @@ function kju (configuration) {
if (this.enabled) this.enable();
// make sure our backup path exists
- path.exists(this.path, function exists (exists) {
+ fs.exists(this.path, function existing(exists) {
if (!exists) {
return self.emit('error', new Error(self.path + ' does not exist.'));
}
@@ -84,19 +83,18 @@ function kju (configuration) {
return self.emit('error', new Error(self.path + ' should end with a slash'));
}
});
-};
+}
-kju.prototype = new EventEmitter2;
-kju.constructor = kju;
+KJU.prototype = new EventEmitter2;
+KJU.constructor = KJU;
/**
* Enable kju
*
* @returns {kju}
* @api public
*/
-
-kju.prototype.enable = function enable () {
+KJU.prototype.enable = function enable() {
if (this.timeout) return this;
this.timeout = setTimeout(this.update.bind(this), this.interval);
@@ -115,8 +113,7 @@ kju.prototype.enable = function enable () {
* @returns {kju}
* @api public
*/
-
-kju.prototype.disable = function disable (nocommit) {
+KJU.prototype.disable = function disable(nocommit) {
if (!this.timeout) return this;
// clean up, the order matters as this.drain() can set a new
@@ -142,7 +139,7 @@ kju.prototype.disable = function disable (nocommit) {
* @api public
*/
-kju.prototype.push = function push () {
+KJU.prototype.push = function push() {
this.length += arguments.length;
Array.prototype.push.apply(this.buffer, arguments);
@@ -161,8 +158,7 @@ kju.prototype.push = function push () {
* @returns {kju}
* @api private
*/
-
-kju.prototype.drain = function drain () {
+KJU.prototype.drain = function drain() {
this.emit('data', this.buffer.splice(0), this.length);
// increase metrics & reset
@@ -181,8 +177,7 @@ kju.prototype.drain = function drain () {
* @return {kju}
* @api public
*/
-
-kju.prototype.forEach = function forEach (fn, that) {
+KJU.prototype.forEach = function forEach(fn, that) {
this.buffer.forEach(fn, that || this);
return this;
@@ -195,8 +190,7 @@ kju.prototype.forEach = function forEach (fn, that) {
* @returns {kju}
* @api private
*/
-
-kju.prototype.update = function update () {
+KJU.prototype.update = function update() {
// don't reinitialize the timeout, we are probably disabled
if (!this.timeout) return this;
@@ -216,7 +210,7 @@ kju.prototype.update = function update () {
// did we reach our maximum interval?
if (this.warnings && this.interval >= this.maximum) {
- process.nextTick(function maximum () {
+ process.nextTick(function maximum() {
self.emit('maximum timeout.warning');
});
}
@@ -229,9 +223,9 @@ kju.prototype.update = function update () {
// did we reach our minimum interval?
if (this.warnings && this.interval <= this.minimum) {
- process.nextTick(function minimum () {
+ process.nextTick(function minimum() {
self.emit('minimum timeout.warning');
- })
+ });
}
}
}
@@ -249,8 +243,7 @@ kju.prototype.update = function update () {
* @returns {Object} object with metrics
* @api public
*/
-
-kju.prototype.metrics = function metrics () {
+KJU.prototype.metrics = function metrics() {
var uptime = this.since ? Date.now() - this.since : 0
, minute = 1000 * 60;
@@ -261,8 +254,8 @@ kju.prototype.metrics = function metrics () {
, 'interval': this.interval
, 'items per minute': (this.processed / minute).toFixed(2)
, 'drains per minute': (this.drained / minute).toFixed(2)
- }
-}
+ };
+};
/**
* Backup the current internal queue, please note that we need to use sync
@@ -273,9 +266,8 @@ kju.prototype.metrics = function metrics () {
*
* @api private
*/
-
-kju.prototype.backup = function backup () {
- if (!this.recover || !this.length || !path.existsSync(this.path)) return;
+KJU.prototype.backup = function backup() {
+ if (!this.recover || !this.length || !fs.existsSync(this.path)) return;
var filename = /(\d+)\.kju$/
, data = JSON.stringify(this.buffer)
@@ -286,12 +278,12 @@ kju.prototype.backup = function backup () {
var files = [];
fs.readdirSync(this.path)
- .filter(function map (file) { return filename.test(file) })
- .map(function map (file) { return +filename.exec(file)[1] })
- .sort(function sort (a, b) { return a - b })
- .forEach(function forEach (file) {
- if (files.indexOf(file) === -1) files.push(file)
- })
+ .filter(function filter(file) { return filename.test(file); })
+ .map(function map(file) { return +filename.exec(file)[1]; })
+ .sort(function sort(a, b) { return a - b; })
+ .forEach(function each(file) {
+ if (files.indexOf(file) === -1) files.push(file);
+ });
// determine sequence number
if (files.length) {
@@ -315,8 +307,7 @@ kju.prototype.backup = function backup () {
*
* @api private
*/
-
-kju.prototype.recovery = function recover () {
+KJU.prototype.recovery = function recover() {
var self = this
, processed = 0
, currently = 0;
@@ -328,12 +319,11 @@ kju.prototype.recovery = function recover () {
* @param {Array} files Files to filter
* @api private
*/
-
- function filter (err, files) {
+ function filter(err, files) {
if (err) return self.emit('error', err);
- var kjud = files.filter(function (file) {
- return /(\d)\.kju$/.test(file);
+ var kjud = files.filter(function filterfiles(file) {
+ return (/(\d)\.kju$/).test(file);
});
// if we don't have any files we don't really need to emit 'recovered' so
@@ -351,9 +341,8 @@ kju.prototype.recovery = function recover () {
* @param {Array} files
* @api private
*/
-
- function read (file, index, files) {
- fs.readFile(self.path + file, function readFile (err, contents) {
+ function read(file, index, files) {
+ fs.readFile(self.path + file, function readFile(err, contents) {
if (err) return done(), self.emit('error', err);
// try to parse the file as JSON, if that doesn't work we have big issue
@@ -365,10 +354,10 @@ kju.prototype.recovery = function recover () {
// care about the clean up process. So I'm not gonna handle the errors
// that could occur there.
self.push.apply(self, todo);
- fs.unlink(self.path + file, function () {});
+ fs.unlink(self.path + file, function ignore(err) {});
} catch (e) {
self.emit('error'
- , new Error('corrupted file, unable to parse contents of ' + file)
+ , new Error('Corrupted file, unable to parse contents of ' + file)
);
}
@@ -381,8 +370,7 @@ kju.prototype.recovery = function recover () {
*
* @api private
*/
-
- function done () {
+ function done() {
if (!--processed) {
self.emit('recovered');
}
@@ -391,11 +379,11 @@ kju.prototype.recovery = function recover () {
}
// check if the path exists and if there are files to filter
- path.exists(this.path, function existsPath (exists) {
+ fs.exists(this.path, function existsPath(exists) {
if (!exists) return;
fs.readdir(self.path, filter);
- })
+ });
};
/**
@@ -404,11 +392,10 @@ kju.prototype.recovery = function recover () {
* @static
* @type {String}
*/
-
-kju.version = '0.0.2';
+KJU.version = '0.0.2';
/**
* Expose the API.
*/
-module.exports = kju;
+module.exports = KJU;
View
@@ -1,23 +1,23 @@
{
"name": "kju"
- , "version": "0.0.2"
+ , "version": "0.0.3"
, "author": "Arnout Kazemier <info@3rd-Eden.com>"
, "description": "Fault tolerant queue that queues data for bulk updates"
- , "homepage": "http://observer.no.de"
+ , "homepage": "http://observe.it"
, "keywords": ["kju", "queue", "bulk", "batch", "updates"]
, "repository": {
"type": "git"
, "url": "https://github.com/observing/kju.git"
}
, "dependencies": {
- "eventemitter2": "0.4.1"
+ "eventemitter2": "0.4.11"
}
, "devDependencies": {
- "should": "0.3.2"
- , "mocha": "*"
+ "chai": "1.4.x"
+ , "mocha": "1.7.x"
, "long-stack-traces": "0.1.2"
}
- , "main": "index"
+ , "main": "lib/kju.js"
, "scripts": {
"test": "make test"
}
Oops, something went wrong.

0 comments on commit 7332a3a

Please sign in to comment.