Skip to content

Commit

Permalink
- Fixed a config bug caused by the array merge from extend
Browse files Browse the repository at this point in the history
- Updated dependencies (especially lodash to 4.x)
close #7
  • Loading branch information
M. Peter committed Mar 31, 2016
1 parent e1f978e commit b133684
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 41 deletions.
20 changes: 5 additions & 15 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@ module.exports = (grunt) ->
# Project configuration.
grunt.initConfig
pkg: grunt.file.readJSON('package.json')
regarde:
watch:
module:
files: ["_src/**/*.coffee"]
tasks: [ "coffee:changed" ]
tasks: [ "coffee:base" ]

coffee:
changed:
expand: true
cwd: '_src'
src: [ '<% print( _.first( ((typeof grunt !== "undefined" && grunt !== null ? (_ref = grunt.regarde) != null ? _ref.changed : void 0 : void 0) || ["_src/nothing"]) ).slice( "_src/".length ) ) %>' ]
# template to cut off `_src/` and throw on error on non-regrade call
# CF: `_.first( grunt?.regarde?.changed or [ "_src/nothing" ] ).slice( "_src/".length )
dest: ''
ext: '.js'

base:
expand: true
cwd: '_src',
Expand Down Expand Up @@ -52,7 +43,7 @@ module.exports = (grunt) ->
main:
src: [ "test/main.js" ]
options:
env:
env:
severity_rsmqworker: "warning"


Expand All @@ -74,7 +65,7 @@ module.exports = (grunt) ->


# Load npm modules
grunt.loadNpmTasks "grunt-regarde"
grunt.loadNpmTasks "grunt-contrib-watch"
grunt.loadNpmTasks "grunt-contrib-coffee"
grunt.loadNpmTasks "grunt-contrib-clean"
grunt.loadNpmTasks "grunt-mocha-cli"
Expand All @@ -85,12 +76,11 @@ module.exports = (grunt) ->
grunt.option('force', not grunt.option('force'))

# ALIAS TASKS
grunt.registerTask "watch", "regarde"
grunt.registerTask "default", "build"
grunt.registerTask "docs", "docker"
grunt.registerTask "clear", [ "clean:base" ]
grunt.registerTask "test", [ "build", "mochacli:main" ]

# build the project
grunt.registerTask "build", [ "clear", "coffee:base", "includereplace" ]
grunt.registerTask "build-dev", [ "clear", "coffee:base", "docs", "test" ]
grunt.registerTask "build-dev", [ "clear", "coffee:base", "docs", "test" ]
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ This is an advanced example showing some features in action.
## Release History
|Version|Date|Description|
|:--:|:--:|:--|
|0.3.8|2015-11-04|Fixed stop behaviour. [Pull#5](https://github.com/mpneuried/rsmq-worker/pull/5). Thanks to [Exinferis](https://github.com/exinferis)|
|0.4.0|2016-03-30|Updated dependencies (especially lodash to 4.x). Fixed a config bug caused by the array merge from `extend` [Issue#7](https://github.com/mpneuried/rsmq-worker/issues/7). Thanks to [Peter Hanneman](https://github.com/timelessvirtues )|
|0.3.8|2015-11-04|Fixed stop behavior. [Pull#5](https://github.com/mpneuried/rsmq-worker/pull/5). Thanks to [Exinferis](https://github.com/exinferis)|
|0.3.7|2015-09-02|Added tests to check the behavior during errors within message processing; Added option `alwaysLogErrors` to prevent console logs if an error event handler was attached. [Issue #3](https://github.com/mpneuried/rsmq-worker/issues/3)|
|0.3.6|2015-09-02|Updated dependencies; optimized readme (thanks to [Tobias Lidskog](https://github.com/tobli) for the [pull #4](https://github.com/mpneuried/rsmq-worker/pull/4))|
|0.3.5|2015-04-27|again ... fixed argument dispatch for `.send()`|
Expand Down
32 changes: 21 additions & 11 deletions _src/lib/rsmq-worker.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
#

# **node modules**
_ = require("lodash")
_isFunction = require( "lodash/isFunction" )
_once = require( "lodash/once" )
_isBoolean = require( "lodash/isBoolean" )
_isArray = require( "lodash/isArray" )
_last = require( "lodash/last" )
_delay = require( "lodash/delay" )

async = require("async")
RSMQ = require("rsmq")

Expand Down Expand Up @@ -57,6 +63,10 @@ class RSMQWorker extends require( "mpbasic" )()
###
constructor: ( @queuename, options )->
super( options )
# hard set of the interval because extend will merge the default with the given elements
if options.interval? and _isArray( options.interval )
@config.interval = options.interval

@ready = false

@waitCount = 0
Expand Down Expand Up @@ -128,7 +138,7 @@ class RSMQWorker extends require( "mpbasic" )()
###
send: ( msg, args... )=>
[ delay, cb ] = args
if _.isFunction( delay )
if _isFunction( delay )
cb = delay
delay = null

Expand Down Expand Up @@ -159,11 +169,11 @@ class RSMQWorker extends require( "mpbasic" )()
@queue.deleteMessage qname: @queuename, id: id, ( err, resp )=>
if err
@error "delete queue message", err
cb( err ) if _.isFunction( cb )
cb( err ) if _isFunction( cb )
return
@debug "delete queue message", resp
@emit( "deleted", id )
cb( null ) if _.isFunction( cb )
cb( null ) if _isFunction( cb )
return
return @

Expand Down Expand Up @@ -300,10 +310,10 @@ class RSMQWorker extends require( "mpbasic" )()
@queue.sendMessage { qname: @queuename, message: msg, delay: delay }, ( err, resp )=>
if err
@error "send pending queue message", err
cb( err ) if cb? and _.isFunction( cb )
cb( err ) if cb? and _isFunction( cb )
return
@emit "new", resp
cb( null, resp ) if cb? and _.isFunction( cb )
cb( null, resp ) if cb? and _isFunction( cb )
return
return

Expand Down Expand Up @@ -362,8 +372,8 @@ class RSMQWorker extends require( "mpbasic" )()
return
, @config.timeout )

_fnNext = _.once ( del = true )=>
if _.isBoolean( del ) or _.isNumber( del )
_fnNext = _once ( del = true )=>
if _isBoolean( del ) or _isNumber( del )
@del( _id ) if del
else if del?
# if there is a return value ant it's not a boolean or number i asume it's an error
Expand Down Expand Up @@ -436,8 +446,8 @@ class RSMQWorker extends require( "mpbasic" )()
if not wait
@waitCount = 0

if _.isArray( @config.interval )
_timeout = if @config.interval[ @waitCount ]? then @config.interval[ @waitCount ] else _.last( @config.interval )
if _isArray( @config.interval )
_timeout = if @config.interval[ @waitCount ]? then @config.interval[ @waitCount ] else _last( @config.interval )
else
if wait
_timeout = @config.interval
Expand All @@ -447,7 +457,7 @@ class RSMQWorker extends require( "mpbasic" )()
@debug "wait", @waitCount, _timeout * 1000
if _timeout >= 0
clearTimeout( @timeout ) if @timeout?
@timeout = _.delay( @interval, _timeout * 1000 )
@timeout = _delay( @interval, _timeout * 1000 )
@waitCount++
else
@interval()
Expand Down
15 changes: 12 additions & 3 deletions _src/test/main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe "----- rsmq-worker TESTS -----", ->
before ( done )->

RSMQWorker = require( "../." )
worker = new RSMQWorker( _queuename, { interval: [ 0, 1 ] } )
worker = new RSMQWorker( _queuename, { interval: [ 0, 1, 5 ] } )

worker.on "ready", ->
done()
Expand All @@ -25,7 +25,16 @@ describe "----- rsmq-worker TESTS -----", ->
return

describe 'Main Tests', ->


# Implement tests cases here
it "check interval config", ( done )->
worker.config.interval.length.should.equal( 3 )
worker.config.interval[ 0 ].should.equal( 0 )
worker.config.interval[ 1 ].should.equal( 1 )
worker.config.interval[ 2 ].should.equal( 5 )
done()
return

# Implement tests cases here
it "first test", ( done )->
_examplemsg = utils.randomString( utils.randRange( 4, 99 ), 3 )
Expand Down Expand Up @@ -54,9 +63,9 @@ describe "----- rsmq-worker TESTS -----", ->

should.equal( msg, _examplemsg )
next()
worker.removeListener( "message", _testFn )
_diff = Math.round( ( Date.now() - _start )/1000 )
_diff.should.be.above(_delay)
worker.removeListener( "message", _testFn )
done()
return

Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rsmq-worker",
"version": "0.3.8",
"version": "0.4.0",
"description": "RSMQ helper to simply implement a worker around the message queue",
"keywords": [],
"homepage": "https://github.com/mpneuried/rsmq-worker",
Expand All @@ -23,19 +23,19 @@
},
"license": "MIT",
"dependencies": {
"async": "1.4.x",
"lodash": "3.x",
"async": "1.5.x",
"lodash": "4.x",
"mpbasic": "0.0.x",
"rsmq": "0.3.x"
"rsmq": "0.7.x"
},
"devDependencies": {
"should": "4.3.x",
"should": "8.x",
"grunt": "0.4.x",
"grunt-regarde": "*",
"grunt-contrib-coffee": "0.13.x",
"grunt-include-replace": "3.0.x",
"grunt-mocha-cli": "1.13.x",
"grunt-docker": "0.0.x",
"grunt-contrib-clean": "0.6.x"
"grunt-contrib-watch": "1.x",
"grunt-contrib-coffee": "1.x",
"grunt-include-replace": "3.x",
"grunt-mocha-cli": "2.x",
"grunt-docker": "0.x",
"grunt-contrib-clean": "1.x"
}
}

0 comments on commit b133684

Please sign in to comment.