簡體   English   中英

Rake任務在本地計算機上運行,​​而不是在Heroku上運行

[英]Rake task working on local machine, not on heroku

這是我簡單的耙任務:

desc 'Create objects from csv'
  task :add_missing_information_from_url, [:url] => [:environment] do |t, args|
    url = args[:url]

    puts "STARTED"

    CSV.new(open(url), :headers => :first_row).to_enum.with_index(1).each do |line, i|
      user = User.find(line['id'])
      next if user.nil?

      user.flag = true
      user.save

      puts "#{i} - #{user.firstname}"
    end
  end

對於初學者來說,沒有任何明智的選擇。 但是由於某種原因,這在Heroku上不起作用。 這是我執行任務的方式(我的名稱空間是dbs):

heroku run rake dbs:add_missing_information_from_url['http://lvh.me/file.csv']

或在開發機器上:

bundle exec rake dbs:add_missing_information_from_url['http://lvh.me/file.csv']

這是運行heroku任務時從控制台獲得的唯一輸出:

Running `rake dbs:add_missing_information_from_url[http://lvh.me/file.csv]` attached to terminal... up, run.7246

執行完任何內容后,返回到我的shell,也沒有保存用戶對象。

但是,當我在開發機器上運行它時,一切正常,從開始打印STARTED開始。

我在這里做錯了什么?

是我還是您的日志實際輸出以下內容:

Running `rake dbs:add_missing_information_from_url[http://lvh.me/file.csv]` attached to terminal... up, run.7246

如果您仔細查看[http://lvh.me/file.csv]中的參數,該參數似乎不是字符串。 您希望您的日志輸出['http://lvh.me/file.csv']

因此,我建議您嘗試像這樣運行任務:

heroku run rake dbs:add_missing_information_from_url['"http://lvh.me/file.csv"']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM