Skip to content

Commit

Permalink
add chaingang status
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Jul 12, 2011
1 parent 64ae35e commit b399199
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/index.coffee
Expand Up @@ -73,6 +73,15 @@ class ChainGang extends Events.EventEmitter

if @active then @perform()

checkStatus: ->
i = 1
s = []
now = new Date
for job in @queue
s.push "#{i}: #{job.name} @ #{now - job.created}s ago (#{job.requests})"
i++
s.join "\n"

# Sets up a timer for the given job, if a timeout is set on the chain.
#
# job - The new Job instance that is getting the timer.
Expand Down
4 changes: 4 additions & 0 deletions test/chain_gang_test.coffee
Expand Up @@ -23,13 +23,17 @@ job = chain.index.foo
assert.equal 1, job.requests
assert.ok job.created?

assert.equal "1: foo @ 0s ago (1)", chain.checkStatus()

# test adding a duplicate item to the queue
called = false
chain.add null, 'foo'
assert.equal false, called
chain.removeListener 'add', cb
assert.equal 2, job.requests

assert.equal "1: foo @ 0s ago (2)", chain.checkStatus()

# test adding a 2nd item to the queue
called = false
a = 0
Expand Down

0 comments on commit b399199

Please sign in to comment.