Ruby on rails 在RoR中的线程中运行刮刀
我的RubyonRails应用程序中有两个scraper,我正在尝试将我的数据scraper运行到不同的线程中。 问题是我的scrapers存储在Ruby on rails 在RoR中的线程中运行刮刀,ruby-on-rails,ruby,ruby-on-rails-5,Ruby On Rails,Ruby,Ruby On Rails 5,我的RubyonRails应用程序中有两个scraper,我正在尝试将我的数据scraper运行到不同的线程中。 问题是我的scrapers存储在app/controllers/services/scrapers文件夹中,我无法在线程中访问此服务。请看下面的代码: threads = [] data.each_key do |office| threads << Thread.new(office, data) do |office1, data1|
app/controllers/services/scrapers
文件夹中,我无法在线程中访问此服务。请看下面的代码:
threads = []
data.each_key do |office|
threads << Thread.new(office, data) do |office1, data1|
data1[office1].each_key do |link|
if (first condition)
Services::Scrapers::FirstScraperService.new.parse(link, data1[office1][link])
elsif (second condition)
Services::Scrapers::SecondScraperService.new.parse(link, data1[office1][link])
end
end
end
end
threads.each { |thr| thr.join }
你能发布你的导演结构吗?这个问题很可能可以通过使用
::服务::…
来解决。试试看。@AkshayGoyal我已经在服务::Scrapers::FirstScraperService
前面上传了这个结构,但它不起作用?@AkshayGoyal我已经尝试过了,但是遇到了另一个问题警告已经初始化了常量服务
和警告:以前的服务定义在这里
app/controllers/services/scrapers