Skip to content

Commit

Permalink
Add timer for running intervalled jobs.
Browse files Browse the repository at this point in the history
  • Loading branch information
esamattis committed Jul 22, 2011
1 parent 5b4ee67 commit 7b21078
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/watcher.coffee
Expand Up @@ -37,6 +37,7 @@ class Watcher extends EventEmitter
@lastRunTimeStamp = 0
@rerun = false
@running = false
@timer = null
@exitstatus = 0
@status = "start"

Expand Down Expand Up @@ -77,6 +78,15 @@ class Watcher extends EventEmitter
timeSinceLastrun = ((new Date()).getTime() - @lastRunTimeStamp) / 1000 / 60
if timeSinceLastrun < @settings.interval
console.log "#{ @name } got change on #{ filepath }, but interval is not due yet. #{ @settings.interval - timeSinceLastrun } minutes left"

if not @timer
console.log "Setting timer", @name
@timer = setTimeout =>
console.log "Manual run from timer", @name
@onModified filepath, True
@timer = null
, @settings.interval * 60 * 1000

return
else
console.log "#{ @name } got change on #{ filepath }"
Expand Down

0 comments on commit 7b21078

Please sign in to comment.