Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 延迟基于页面结果的方法_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails 延迟基于页面结果的方法

Ruby on rails 延迟基于页面结果的方法,ruby-on-rails,ruby,Ruby On Rails,Ruby,我正在使用“net/http”和“uri”从NCBI的在线Blast工具检索结果。为此,我必须搜索一个html页面,检查其中一行是“Status=WAITING”还是“Status=READY”。Blast工具完成后,状态将更改为就绪,结果将发布在html页面上 我有一个工作版本来检查状态,然后检索我需要的信息,但是它效率很低,而且当我认为可以将它们合并为一种方法时,它被分成两种方法 def waitForBlast(rid) get = Net::HTTP.post_form(URI.

我正在使用“net/http”和“uri”从NCBI的在线Blast工具检索结果。为此,我必须搜索一个html页面,检查其中一行是“Status=WAITING”还是“Status=READY”。Blast工具完成后,状态将更改为就绪,结果将发布在html页面上

我有一个工作版本来检查状态,然后检索我需要的信息,但是它效率很低,而且当我认为可以将它们合并为一种方法时,它被分成两种方法

def waitForBlast(rid)
    get = Net::HTTP.post_form(URI.parse('http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?'), {:RID => "#{rid}", :CMD => 'Get'})
    get.body.each{|line| (waitForBlast(rid) if line.strip == "Status=WAITING") if line[/Status=/]}
end

def returnBlast(rid)
    blast_array = Array.new
    get = Net::HTTP.post_form(URI.parse('http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?'), {:RID => "#{rid}", :CMD => 'Get'})
    get.body.each{|line| blast_array.push(line[/<a href=#\d+>/][/\d+/]) if line[/<a href=#\d+>/]}
    return blast_array
end
def waitForBlast(rid)
get=Net::HTTP.post_表单(URI.parse('http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?),{:RID=>“#{RID}”,:CMD=>'Get'})
get.body.each{| line |(waitForBlast(rid)if line.strip==“Status=WAITING”)if line[/Status=/]
终止
def returnBlast(rid)
blast_array=array.new
get=Net::HTTP.post_表单(URI.parse('http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?),{:RID=>“#{RID}”,:CMD=>'Get'})
get.body.each{| line | blast_数组.push(line[/][/\d+/])如果line[/]}
返回blast_数组
终止
第一个方法检查状态,这是我主要关心的问题,因为它是递归的。我相信(如果我错了,请纠正我),按原样设计需要太多的计算能力,而我所需要的只是某种方法,以相同的方法重新检查结果(添加时间延迟是一个额外的好处)。第二种方法很好,但我更愿意以某种方式将其与第一种方法相结合。非常感谢您的帮助。

请查看实施情况。他就是这样做的:

 res='http://www.ncbi.nlm.nih.gov/blast/Blast.cgi?CMD=Get&FORMAT_OBJECT=SearchInfo&RID=' + @rid
 while status = open(res).read.scan(/Status=(.*?)$/).to_s=='WAITING'
   @logger.debug("Status=WAITING")
   sleep(3)
 end   

我认为使用字符串扫描器可能比遍历页面中的每一行更有效率,但我还没有研究它的实现,所以我可能错了

你能给我解释一下@logger.debug(“Status=Waiting”)吗。我对它不熟悉。它只是将
Status=WAITING
打印到ruby控制台。看,不看HTML很难说,但我想你可以通过使用字符串搜索来简化搜索。此外,对于除最琐碎的解析任务之外的任何任务,解析器都将在长期内为您节省很多痛苦。我推荐Nokogiri。另外,看看如何使用Ruby内置的
Open::URI
。与
Net::HTTP
URI
相比,它更易于使用。此外,如果
rid
还不是字符串,则可以将
“{rid}”
简化为
rid
rid.to