私はこの方法があります:Delayed Jobを使用してRuby on Railsの特定の時間にメソッドを実行するにはどうすればいいですか?
module ApplicationHelper
class AtualizarBanco
require 'open-uri'
require 'nokogiri'
require 'net/http'
def updatetable
retorno = Net::HTTP.get_response(URI.parse('http://www.olx.com.br/loja/id/174483'))
if retorno.code == "200"
site = open ('http://www.olx.com.br/loja/id/174483')
site_lido = site.read
site_html = Nokogiri::HTML(site_lido)
vetor_preco = site_html.at_css('#main-ad-list').css('.item').css('.OLXad-list-price').map{|q| q.text.sub!(" R$ ", "").sub!(".", "").to_f}
vetor_texto = site_html.at_css('#main-ad-list').css('.item').css('.OLXad-list-title').map{|lista| lista.text.strip}
vetor_catg = site_html.css('#main-ad-list .OLXad-list-line-2').xpath('p[@class="text detail-category"]').map{|q| q.children.first.text.strip}
vetor_img = site_html.css('#main-ad-list .OLXad-list-image-box').xpath('span|img[@class="image"]/@src|img[@class="image lazy"]/@data-original').map(&:text)
i = 0
if ((vetor_preco.length == vetor_texto.length) && (vetor_preco.length == vetor_catg.length) && (vetor_preco.length == vetor_img.length))
while i < vetor_preco.length
@prod = Produto.new(nm_produto: vetor_texto[i], preco: vetor_preco[i], categoria: vetor_catg[i], img_produto: vetor_img[i])
i += 1
if (@prod.valid?)
@prod.save
end
end
end
end
end
end
end
をそして私は5:30 GMTで、このメソッドを毎日実行したいです。
私はいくつかの検索をしましたが、Delayed Jobの宝石とCronスケジューラについて知っていましたが、私が必要とするものをどのように使っているかはわかりませんでした。
遅延ジョブはRails 5.0.0.1でもうまく機能しますか? バージョン3.0+と4.2についてのドキュメントでは、それが "4.2以上"か4.2かどうかはわかりませんでした。
私は、遅延雇用宝石を「遅延雇用」と呼んでいるのか、宝石「delayed_job_active_record」を使用する必要があるのか、config.active_job.queue_adapterを変更する必要があるかどうかもわかりません。
:run_atパラメータが特定の時刻コマンドを受け入れるかどうかについては説明していませんが、例では「5分後」や「2時間後」のようなものしかありません。
助けが必要ですか?
ようになります。 私はそれをupdatetable.rakeというファイルに入れる必要がありますか? –
あなたはもっと詳しい情報[here](http://guides.rubyonrails.org/command_line.html#custom-rake-tasks) –
もう1つ、この "5:30"の標準時はすでにGMTです、または私はそれを設定する必要がありますか? –