def wait_until_state(task_id, state, max_nap)
      blink_time = 5 # wake up and scan
      nap_start = Time.now
      state_method = method("task_#{state}?".to_sym)
      loop do
        break if state_method.call(task_id)
        raise TaskNotDoneError, "Task: #{task_id} has taken too long to complete!" if Time.new > (nap_start + max_nap)

        sleep blink_time
      end
      task_id
    end
def wait_until_state(task_id, state, max_nap)
      blink_time = 5 # wake up and scan
      nap_start = Time.now
      state_method = method("task_#{state}?".to_sym)
      loop do
        break if state_method.call(task_id)
        raise TaskNotDoneError, "Task: #{task_id} has taken too long to complete!" if Time.new > (nap_start + max_nap)

        sleep blink_time
      end
      task_id
    end
Blocks until a task reaches a specific status
 @param [Integer] task_id
 @param [String] state state to reach
 @param [Integer] max_nap seconds to try before giving up