Skip to content

Commit

Permalink
job objects track how many requests they get, and when they were queued
Browse files Browse the repository at this point in the history
  • Loading branch information
technoweenie committed Jul 12, 2011
1 parent a73f025 commit 64ae35e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.coffee
Expand Up @@ -44,6 +44,8 @@ class ChainGang extends Events.EventEmitter
@queue.push job
@emit 'add', job.name

job.requests += 1

if callback
job.callbacks.push callback

Expand Down Expand Up @@ -106,6 +108,8 @@ class Job
@callbacks = []
@timedOut = false
@timer = @chain.setTimerFor @
@requests = 0
@created = new Date

# Performs the Job, running any callbacks. See finish().
#
Expand Down
5 changes: 5 additions & 0 deletions test/chain_gang_test.coffee
Expand Up @@ -19,11 +19,16 @@ chain.addListener 'add', cb
chain.add 'work', 'foo'
assert.ok called

job = chain.index.foo
assert.equal 1, job.requests
assert.ok job.created?

# 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

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

0 comments on commit 64ae35e

Please sign in to comment.