code: def wait_task_completion(taskid)
        errormsg = nil
        task = {}
  
        loop do
          task = get_task(taskid)
          break if task[:status] != 'running'
          sleep 1
        end
  
        if task[:status] == 'error'
          errormsg = task[:response].css("Error").first
          errormsg = "Error code #{errormsg['majorErrorCode']} - #{errormsg['message']}"
        end
  
        { :status => task[:status], :errormsg => errormsg,
          :start_time => task[:start_time], :end_time => task[:end_time] }
      end
docs: Poll a given task until completion