Ruby (rails) non-blocking recursive algorithm? -


i've written following pseudo-ruby illustrate i'm trying do. i've got computers, , want see if anything's connected them. if nothing connected them, try again 2 attempts, , if that's still case, shut down.

this big deployment recursive timer running hundreds of nodes. want check, approach sound? generate tonnes of threads , eat lots of ram while blocking worker processes? (i expect running delayed_job)

check_status(0)   def check_status(i)   if instance.connected.true? return    if instance.connected.false? , < 3     wait.5.minutes     instance.check_status(i+1)   else      instance.shutdown     return   end end 

there not going large problem when maximum recursion depth here 3. should fine. recursing method not create threads, each call store more information call stack, , resources used storage run out. not after 3 calls though, quite safe.

however, there no need recursion solve problem. following loop should well:

def check_status   return if instance.connected.true?   2.times      wait.5.minutes     return if instance.connected.true?   end   instance.shutdown end 

Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -