How to export data to CSV and upload to a separate FTP site from Heroku?

How to export data to CSV and upload to a separate FTP site from Heroku?



require 'csv'
require 'net/ftp'

task :export_data => :environment do
  path = "tmp/"
  filename = 'test_' + Date.today.to_s + '.dat'

  messages = Message.where( :foo => bar)
  CSV.open(path + filename, "wb", :col_sep => '|') do |csv|

    messages.each do |m|
      csv << [m.id.to_s, m.name]
      puts "Processing message " + m.id.to_s
    end
  end

  puts "Uploading " + filename
  ftp = Net::FTP.new('ftp.hostname.com')
  ftp.login(user = "******", passwd = "*******")
  ftp.puttextfile(path + filename, filename)
  ftp.quit()

  puts "Finished."
end

Starting process with command `rake jobs:work`
2011-10-17T21:17:11+00:00 app[worker.1]: (in /app)
2011-10-17T21:17:13+00:00 heroku[worker.1]: State changed from starting to up
2011-10-17T21:17:13+00:00 app[worker.1]: rake aborted!
2011-10-17T21:17:13+00:00 app[worker.1]: Don't know how to build task 'jobs:work'
2011-10-17T21:17:13+00:00 app[worker.1]: /usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:1720:in `[]'
2011-10-17T21:17:13+00:00 app[worker.1]: /usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2040:in `invoke_task'
2011-10-17T21:17:13+00:00 app[worker.1]: /usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2019:in `block (2 levels) in top_level'
2011-10-17T21:17:13+00:00 app[worker.1]: /usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2019:in `each'
2011-10-17T21:17:13+00:00 app[worker.1]: /usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2019:in `block in top_level'
2011-10-17T21:17:13+00:00 app[worker.1]: /usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
2011-10-17T21:17:13+00:00 app[worker.1]: /usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:2013:in `top_level'
2011-10-17T21:17:13+00:00 app[worker.1]: /usr/ruby1.9.2/lib/ruby/1.9.1/rake.rb:1992:in `run'
2011-10-17T21:17:13+00:00 app[worker.1]: /usr/ruby1.9.2/bin/rake:31:in `<main>'
2011-10-17T21:17:13+00:00 heroku[worker.1]: Process exited
2011-10-17T21:17:14+00:00 heroku[worker.1]: State changed from up to crashed

2011-10-17T21:17:13+00:00 app[worker.1]: Don't know how to build task 'jobs:work'

Comments

Popular posts from this blog

How to change this to <%Html.ActionLink%> in my asp.net mvc application ?