Skip to content
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

initial demo of new runner-adapter logic with fs adapter #74

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
8085431
initial demo of new runner-adapter logic with fs adapter
amv Jul 5, 2014
650e025
refactor component to accept more than one worker
amv Jul 13, 2014
a885d9a
db specific ejector logic for #65
amv Jul 13, 2014
6ea144e
moved and renamed test files for clarity #68
amv Jul 15, 2014
bbaba29
resolve controller as part of config initialize
amv Jul 16, 2014
72098f6
added global spawn pool with teardown
amv Jul 19, 2014
d389348
runner: fixes and stored original values on first update
amv Jul 19, 2014
5a53609
small refactoring for injector
amv Jul 19, 2014
920dc3d
allow passing adapter to config as an object
amv Jul 19, 2014
2cc814f
moved db initialization to component constructor
amv Jul 19, 2014
1551491
mostly tested fs adapter
amv Jul 19, 2014
4cc508f
reorder make test to "fix" problems
amv Jul 19, 2014
61d509f
changed adapter test interface
Jul 19, 2014
f50d281
first adapter test for ejector
Jul 19, 2014
317d825
removed pre_test and suite_teardown from adapter tests
amv Jul 19, 2014
1a4a9f6
extended adapter test interface, made adapter configurable via env
amv Jul 19, 2014
11c8501
refactored date parsing to injector instead of adapter
amv Jul 19, 2014
2a65835
make sure workers are registered after db initialize
amv Jul 20, 2014
b12b698
after should override at in task
amv Jul 20, 2014
f40e182
refactored sqlite adapter to have the test functions, and adopt domai…
Jul 19, 2014
0cf28ba
config init should not change config anymore
amv Jul 20, 2014
0e5ec8f
fs adapter should tell why it cant lock
amv Jul 20, 2014
4b1af20
refactored some test setup and teardown functions
amv Jul 20, 2014
ff23da8
component-helper for tests
amv Jul 20, 2014
c109914
first system smoke test
amv Jul 20, 2014
323a9d7
execute adapter teardown at start of adapter tests
amv Jul 20, 2014
81c1391
new README lead in + chapter reordering
amv Aug 9, 2014
b7e37df
Test build for fs-adapter deployment
tstarck Sep 12, 2014
1c387ac
Ran through code with jshint and closure-linter
tstarck Sep 16, 2014
302a9d0
Convert tabs and remove trailing whitespace
tstarck Sep 16, 2014
520a9d4
Another fs-adapter build
tstarck Sep 16, 2014
345dd4d
Fix string format fail
tstarck Sep 16, 2014
88725fc
Add directory and dependecies
tstarck Sep 16, 2014
99ae743
Do not require dbopt in configuration
tstarck Sep 16, 2014
d8ddf2f
Squash evil comparison operators
tstarck Sep 17, 2014
0cf5eb0
It runs - ship it
tstarck Sep 17, 2014
eaf8bde
show real month number in fs storage path
amv Oct 30, 2014
705afb8
format fs date path to sort to correct order
amv Oct 30, 2014
cdcb24e
correctly traverse subdirs of older fs tree branches
amv Oct 30, 2014
3d0515a
fix runner lock releasing with NaN runner_retry_count
amv Oct 30, 2014
de5f126
fixed test test data to match adapter always giving "at"
amv Oct 30, 2014
4482acf
Make logging at least a little bit less horrible
tstarck Oct 31, 2014
06dea6a
Version bump and release
tstarck Oct 31, 2014
a4a3954
Remove unset variable
tstarck Nov 4, 2014
1055997
Show complete payload in debug log
tstarck Nov 11, 2014
d9cf00c
Replace external binaries with js code
tstarck Nov 25, 2014
29d7d9a
Directory recursion in sorted order
tstarck Nov 26, 2014
8f5122b
Added error logging and parseint with radix
tstarck Nov 26, 2014
959e555
API functions to top
tstarck Nov 27, 2014
4880c0e
Remove pointless fs.exists()
tstarck Nov 27, 2014
70e2b92
Cut embarrassingly long lines
tstarck Nov 27, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,11 @@ help:
@echo ' clean-docker - Remove docker marker files (docker directory)'
@echo ''
@echo 'Test targets:'
@echo ' test - Run all tests that do not require docker'
@echo ' images (unit + e2e + blackbox)'
@echo ' test - Run unit and integration tests'
@echo ' test-full - Run unit, integration and system tests'
@echo ' unit-test - Run unit tests'
@echo ' e2e-test - Run end-to-end tests'
@echo ' blackbox-test - Run blackbox tests'
@echo ' docker-test - Run tests requiring docker containers'
@echo ' integration-test - Run integration tests'
@echo ' system-test - Run system tests'
@echo ' coverage - Generate cobertura test coverage reports'
@echo ' (runs all tests)'
@echo ' html-coverage - Generate cobertura html reports'
Expand All @@ -51,19 +50,23 @@ help:

.PHONY: test
test: node_modules
$(MOCHA) $(MOCHA_PARAMS) test/e2e test/blackbox test/unit
$(MOCHA) $(MOCHA_PARAMS) test/*/integration* test/*/unit*

.PHONY: test-full
test-full: node_modules
$(MOCHA) $(MOCHA_PARAMS) test

.PHONY: unit-test
unit-test: node_modules
$(MOCHA) $(MOCHA_PARAMS) test/unit
$(MOCHA) $(MOCHA_PARAMS) test/*/unit*

.PHONY: e2e-test
e2e-test: node_modules
$(MOCHA) $(MOCHA_PARAMS) test/e2e
.PHONY: integration-test
integration-test: node_modules
$(MOCHA) $(MOCHA_PARAMS) test/*/integration*

.PHONY: blackbox-test
blackbox-test: node_modules
$(MOCHA) $(MOCHA_PARAMS) test/blackbox
.PHONY: system-test
system-test: node_modules
$(MOCHA) $(MOCHA_PARAMS) test/system

.PHONY: log-delayed
log-delayed: node_modules
Expand Down
308 changes: 195 additions & 113 deletions README.md

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions bin/gearslothd
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@

var config = require('../lib/config');
var daemon = require('../lib/daemon');
var log = require('../lib/log');

try {
var conf = config.initialize(process.argv);
if (!conf) {
process.exit(0);
}
conf = config.resolveController(conf);
config.initializeDb(conf, function(err, conf) {
if (err)
throw new Error('Error initializing database adapter:', err.message);
daemon.initialize(conf);
});
} catch (err) {
daemon.initialize(conf);
}
catch (err) {
console.error('gearslothd:', err.message);
process.exit(1);
}

31 changes: 31 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
gearsloth (0.4.1-1) unstable; urgency=low

* Show complete payload in debug log

-- Tuomas Starck <[email protected]> Tue, 11 Nov 2014 17:10:17 +0200

gearsloth (0.4.0-1) unstable; urgency=low

* Many fixes for fs-adapter
* A little bit less horrible logging

-- Tuomas Starck <[email protected]> Fri, 31 Oct 2014 15:25:35 +0000

gearsloth (0.3.6-1) unstable; urgency=low

* New release after fixes

-- Tuomas Starck <[email protected]> Wed, 17 Sep 2014 08:29:29 +0000

gearsloth (0.3.5-1) unstable; urgency=low

* Another test build for fs-adapter

-- Tuomas Starck <[email protected]> Tue, 16 Sep 2014 06:07:08 +0000

gearsloth (0.3.3-1) unstable; urgency=low

* Test build for fs-adapter deployment

-- Tuomas Starck <[email protected]> Fri, 12 Sep 2014 13:18:15 +0000

gearsloth (0.2.4-1) unstable; urgency=low

* Example configurations
Expand Down
6 changes: 6 additions & 0 deletions debian/gearsloth.postinst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh -e

USERNAME=gearsloth
FS_ADAPTER_DIR=/usr/lib/gearsloth/fs-adapter

if [ "$1" != "configure" ]; then
exit 0
Expand All @@ -10,4 +11,9 @@ if ! getent passwd $USERNAME >/dev/null; then
adduser --system --no-create-home $USERNAME
fi

if [ ! -d $FS_ADAPTER_DIR ]; then
mkdir -p $FS_ADAPTER_DIR
chown $USERNAME:root $FS_ADAPTER_DIR
fi

exit 0
3 changes: 3 additions & 0 deletions debian/gearsloth.postrm
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/sh -e

FS_ADAPTER_DIR=/usr/lib/gearsloth/fs-adapter

case $1 in
purge)
rm -f /etc/gearsloth/gearsloth.json
rmdir --ignore-fail-on-non-empty /etc/gearsloth
rmdir --ignore-fail-on-non-empty $FS_ADAPTER_DIR
deluser --quiet gearsloth >/dev/null 2>&1 || true
;;
esac
Expand Down
2 changes: 1 addition & 1 deletion debian/gearsloth.upstart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ script
set -e
FIFO=`mktemp --dry-run`
mkfifo $FIFO
(logger -t gearsloth -p local7.info <$FIFO &)
(logger -t sloth -p local7.info <$FIFO &)
exec 2>$FIFO
exec >$FIFO
rm $FIFO
Expand Down
5 changes: 2 additions & 3 deletions debian/install
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package.json usr/lib/nodejs/gearsloth
bin usr/lib/nodejs/gearsloth
lib usr/lib/nodejs/gearsloth

node_modules/async usr/lib/nodejs/gearsloth/node_modules
node_modules/underscore usr/lib/nodejs/gearsloth/node_modules
node_modules/gearman-coffee usr/lib/nodejs/gearsloth/node_modules
node_modules/mysql usr/lib/nodejs/gearsloth/node_modules

examples/initialize-mysql.sql etc/gearsloth
examples/dual-mysql-and-gearman.json etc/gearsloth
examples/simple-sqlite.json etc/gearsloth
30 changes: 15 additions & 15 deletions examples/sqlite-adapter-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ function afterInit(err, dbconn) {
log.debug('sqlite-example', err);
return;
}
var example_task = {
// at: new Date(),
after: 0,
func_name: 'log',
payload: 'kittehs',
controller:'special',
strategy_options:{
retry:true,
times:3
}
};

var example_task = {
// at: new Date(),
after: 0,
func_name: 'log',
payload: 'kittehs',
controller:'special',
strategy_options:{
retry:true,
times:3
}
};

dbconn.saveTask(example_task, function(err) {
log.debug('sqlite-example', 'Error:', err.message);
log.debug('sqlite-example', 'Error:', err.message);
log.debug('sqlite-example', "Task saved: " + new Date());
});

var stop = dbconn.listenTask(function (err, task) {
if (err) {
log.debug('sqlite-example', err);
return;
}

log.debug('sqlite-example', "Recieved task:");
console.log(task);
console.log(new Date());
Expand Down
52 changes: 28 additions & 24 deletions lib/adapters/composite.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ function Compositeadapter(config, databases) {
*
* @param {Object} config - Configuration object as passed from config.js
* @param {Function} callback
* @param {Object} config_helper - A helper to use for initializing adapters (for testing)
* @param {Object} config_helper - A testing helper to use for initializing
*/

function initialize(config, callback, config_helper) {
config_helper = config_helper || require('../config/index');

if(!checkConfSanity(config)) {
callback(new Error('conf.dbopt is not sane, can\'t initialize composite adapter'));
if (!checkConfSanity(config)) {
var msg = 'conf.dbopt is not sane, can\'t initialize composite adapter';
callback(new Error(msg));
return;
}

populateDatabasesArray(config, config_helper, function(err, databases) {
if(err)
if (err)
return callback(err);
var adapter = new Compositeadapter(config, databases);
callback(null, adapter);
Expand All @@ -52,19 +53,22 @@ Compositeadapter.prototype.saveTask = function(task, callback, failcounter) {
failcounter = isNaN(failcounter) ? 0 : failcounter;

// this prevents the function from being called recursively indefinitely :P
if(failcounter >= this._databaseCount()) {
if (failcounter >= this._databaseCount()) {
callback(new Error('No databases available (maybe they are all down?)'));
return;
}

var db = this._pickDb();
db.saveTask(task, function(err, row_id) {
if(err) {
log.err('composite-adapter', 'Unreachable database \''+ db.db_id +'\': ' + err.message);
_this.saveTask(task, callback, ++failcounter); // Call saveTask recursively until a working
return; // database is found.
if (err) {
var msg = 'Unreachable database ' + db.db_id + ':\n';
log.err('composite-adapter', msg + err.message);

// call saveTask recursively until a working database is found
_this.saveTask(task, callback, ++failcounter);
return;
}
callback(null, row_id);
callback(null, row_id);
});
};

Expand All @@ -77,7 +81,7 @@ Compositeadapter.prototype.saveTask = function(task, callback, failcounter) {
Compositeadapter.prototype.listenTask = function(callback) {
_.each(this._databases, function(db, db_id) {
db.listenTask(function(err, task) {
if(err) callback(err);
if (err) callback(err);
else {
var task_id = task.id;
task.id = {
Expand All @@ -100,8 +104,8 @@ Compositeadapter.prototype.listenTask = function(callback) {

Compositeadapter.prototype.updateTask = function(task, callback) {
var db = this._findDbById(task.id.db_id);
if(!db) {
callback(new Error('There is no database available with id ' + task.id.db_id));
if (!db) {
callback(new Error('No database available with id ' + task.id.db_id));
return;
}
task.id = task.id.task_id;
Expand All @@ -117,8 +121,8 @@ Compositeadapter.prototype.updateTask = function(task, callback) {

Compositeadapter.prototype.completeTask = function(task, callback) {
var db = this._findDbById(task.id.db_id);
if(!db) {
callback(new Error('There is no database available with id ' + task.id.db_id));
if (!db) {
callback(new Error('No database available with id ' + task.id.db_id));
return;
}
task.id = task.id.task_id;
Expand All @@ -127,8 +131,8 @@ Compositeadapter.prototype.completeTask = function(task, callback) {

Compositeadapter.prototype.disableTask = function(task, callback) {
var db = this._findDbById(task.id.db_id);
if(!db) {
callback(new Error('There is no database available with id ' + task.id.db_id));
if (!db) {
callback(new Error('No database available with id ' + task.id.db_id));
return;
}
task.id = task.id.task_id;
Expand All @@ -154,26 +158,26 @@ Compositeadapter.prototype._databaseCount = function() {

function checkConfSanity(config) {
return (config.dbopt &&
(config.dbopt instanceof Array) &&
config.dbopt.length > 0);
(config.dbopt instanceof Array) &&
config.dbopt.length > 0);
}

function populateDatabasesArray(config, config_helper, callback) {
var databases = {};

async.each(config.dbopt, function(dbconf, callback) {
if(!dbconf.db || dbconf.db_id === null) {
if (!dbconf.db ||  dbconf.db_id === null) {
callback(new Error('Invalid database config: db or db_id missing'));
}
config_helper.initializeDb(dbconf, function(err, augmented_conf) {
if(err) {
return callback(new Error('Could not initialize a db connection: ' + err.message));
if (err) {
var msg = 'Could not initialize database connection';
return callback(new Error(msg + '\n' + err.message));
}
databases[dbconf.db_id] = augmented_conf.dbconn;
callback(null);
});
}, function(err) {
callback(err, databases);
callback(err, databases);
});
}

Loading