This repository has been archived by the owner on Nov 29, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '0cc06c8a0b0c1de827af7a84d6109f6c94b7324a' as 'archived_…
…PhantRepos/phant-reaper'
- Loading branch information
Showing
8 changed files
with
216 additions
and
0 deletions.
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
tmp | ||
/node_modules/ | ||
*.swp | ||
npm-debug.log |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"curly": true, | ||
"eqeqeq": true, | ||
"immed": true, | ||
"latedef": "func", | ||
"newcap": true, | ||
"noarg": true, | ||
"sub": true, | ||
"undef": true, | ||
"unused": true, | ||
"boss": true, | ||
"eqnull": true, | ||
"node": true | ||
} |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
language: node_js | ||
node_js: | ||
- '0.10' | ||
before_script: | ||
- npm install -g grunt-cli | ||
notifications: | ||
email: | ||
recipients: | ||
- [email protected] | ||
on_success: change | ||
on_failure: change |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
module.exports = function (grunt) { | ||
// Show elapsed time at the end | ||
require('time-grunt')(grunt); | ||
// Load all grunt tasks | ||
require('load-grunt-tasks')(grunt); | ||
|
||
// Project configuration. | ||
grunt.initConfig({ | ||
nodeunit: { | ||
files: ['test/**/*_test.js'] | ||
}, | ||
jshint: { | ||
options: { | ||
jshintrc: '.jshintrc', | ||
reporter: require('jshint-stylish') | ||
}, | ||
gruntfile: { | ||
src: 'Gruntfile.js' | ||
}, | ||
lib: { | ||
src: ['lib/**/*.js'] | ||
}, | ||
test: { | ||
src: ['test/**/*.js'] | ||
} | ||
}, | ||
watch: { | ||
gruntfile: { | ||
files: '<%= jshint.gruntfile.src %>', | ||
tasks: ['jshint:gruntfile'] | ||
}, | ||
lib: { | ||
files: '<%= jshint.lib.src %>', | ||
tasks: ['jshint:lib', 'nodeunit'] | ||
}, | ||
test: { | ||
files: '<%= jshint.test.src %>', | ||
tasks: ['jshint:test', 'nodeunit'] | ||
} | ||
} | ||
}); | ||
|
||
// Default task. | ||
grunt.registerTask('default', ['jshint', 'nodeunit']); | ||
|
||
}; |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# phant-reaper [![Build Status](https://secure.travis-ci.org/sparkfun/phant-reaper.png?branch=master)](http://travis-ci.org/sparkfun/phant-reaper) | ||
|
||
kills old phant stream metadata and data if the stream hasn't been pushed to in a while | ||
|
||
## Getting Started | ||
Install the module with: `npm install phant-reaper` | ||
|
||
## Contributing | ||
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). | ||
|
||
## License | ||
Copyright (c) 2014 SparkFun Electronics. Licensed under the GPL v3 license. |
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* phant-reaper | ||
* https://github.com/sparkfun/phant-reaper | ||
* | ||
* Copyright (c) 2014 SparkFun Electronics | ||
* Licensed under the GPL v3 license. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/**** Module dependencies ****/ | ||
var util = require('util'), | ||
events = require('events'); | ||
|
||
/**** Make Reaper an event emitter ****/ | ||
util.inherits(Reaper, events.EventEmitter); | ||
|
||
/**** app prototype ****/ | ||
var app = Reaper.prototype; | ||
|
||
/**** Expose Reaper ****/ | ||
exports = module.exports = Reaper; | ||
|
||
function Reaper(options) { | ||
|
||
if (! (this instanceof Reaper)) { | ||
return new Reaper(options); | ||
} | ||
|
||
events.EventEmitter.call(this); | ||
|
||
util._extend(this, options || {}); | ||
|
||
} | ||
|
||
app.created = 7 * 24 * 60 * 60 * 1000; // 7 days | ||
app.pushed = 31540000000; // 1 year | ||
app.metadata = false; | ||
app.storage = false; | ||
|
||
app.reap = function() { | ||
|
||
var self = this, | ||
now = new Date(); | ||
|
||
this.metadata.each(function(err, stream) { | ||
|
||
var last = new Date(stream.last_push), | ||
created = new Date(stream.date); | ||
|
||
if(err) { | ||
return self.emit('error', err); | ||
} | ||
|
||
// leave it alone if it was created recently | ||
if ((now.getTime() - created.getTime()) < self.created) { | ||
return; | ||
} | ||
|
||
// leave it alone if it has pushed recently | ||
if ((now.getTime() - last.getTime()) < self.pushed) { | ||
return; | ||
} | ||
|
||
self.metadata.delete(stream.id, function(err) { | ||
|
||
if(err) { | ||
return self.emit('error', err); | ||
} | ||
|
||
self.storage.clear(stream.id); | ||
|
||
self.emit('delete', stream.id); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}; | ||
|
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "phant-reaper", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"description": "clears unused phant streams", | ||
"homepage": "https://github.com/sparkfun/phant-reaper", | ||
"bugs": "https://github.com/sparkfun/phant-reaper/issues", | ||
"author": { | ||
"name": "Todd Treece", | ||
"email": "[email protected]", | ||
"url": "http://uniontownlabs.org" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/sparkfun/phant-reaper" | ||
}, | ||
"license": "GPL-3.0", | ||
"devDependencies": { | ||
"grunt": "^0.4.4", | ||
"grunt-contrib-jshint": "~0.7.0", | ||
"grunt-contrib-nodeunit": "~0.2.0", | ||
"grunt-contrib-watch": "~0.5.0", | ||
"load-grunt-tasks": "~0.2.0", | ||
"time-grunt": "~0.2.0", | ||
"jshint-stylish": "~0.1.3" | ||
}, | ||
"engines": { | ||
"node": "^0.10.29" | ||
}, | ||
"scripts": { | ||
"test": "grunt" | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
archived_PhantRepos/phant-reaper/test/phant_reaper_test.js
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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
var Reaper = require('../index.js'); | ||
|
||
exports.reaper = { | ||
setUp: function(done) { | ||
done(); | ||
}, | ||
'no args': function(test) { | ||
test.expect(1); | ||
test.ok(Reaper, 'should be ok'); | ||
test.done(); | ||
} | ||
}; |