我使用Typheus处理一个包含十几个请求的九头蛇队列。
我使用on_body回调来流式传输响应。
当然,在不中止队列中所有其他请求的情况下,中止此回调中的当前请求(即达到最大文件大小...)的最佳方法是什么?
hydra = Typhoeus::Hydra.hydra
urls.each do |url|
request = Typhoeus::Request.new(url, followlocation: true, timeout: 5, connecttimeout: 5)
request.on_body do |chunk, response|
#
# How to conditionally abort the request here ?
#
end
hydra.queue request
end
hydra.run
2条答案
按热度按时间pcrecxhr1#
There is no way at the moment. According to http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTWRITEFUNCTION it would be enough to return an invalid size. But that is not an option yet in Typhoeus since the callback itself is wrapped and it always returns the correct size: https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/callbacks.rb#L37-48.
编辑:Ethon 0.7.1能够中止on_body回调中的请求:https://github.com/typhoeus/ethon/commit/6117872004c9ed1dac0ac15542dffc10177d8eae.
c0vxltue2#
根据README,Typheus现在有一种方法来中断on_body回调。
返回
:abort
符号: