在一个下雨的星期六下午,我遇到了以下问题。当我在rails控制台中运行时,两个操作一个接一个地失败(第二个是)。
我正在做的是
rails console
要求'extractor / myfile'
MyClass.Task1
(在这个阶段,Evernthing很好)
MyClass.Task2
(只是得到[]作为很棒的答案)
当我这样做时,神奇的是:
退出
轨道控制台
要求'extractor / myfile'
MyClass.Task2
它不会失败(正常运行)。日志似乎没有提供太多帮助,所以想知道是什么让事情失败。在rake任务中使用它们并没有多大帮助。很想听听社区的消息。
这是课程中的两个功能:
require 'fileutils'
require 'net/ftp'
# these are for the AWS upload
require 'rubygems'
require 'aws-sdk'
# This is a simple logging class
require 'logger'
# Location for the Logger
class FileUpload
def self.download_from_s3
FileUtils::mkdir_p("lib/extractor/temp/dataupload") unless Dir.pwd.include? "lib/extractor/temp/dataupload"
Dir.chdir("lib/extractor/temp/dataupload" ) unless Dir.pwd.include? "/lib/extractor/temp/dataupload"
# Get an instance of the S3 interface.
s3 = AWS::S3.new(:access_key_id => 'access',
:secret_access_key => 'secret')
my_bucket = s3.buckets['bucketname']
# Upload a file.
#key = File.basename(filename)s3.buckets[bucket_name].objects[key].read(:file => filename)
File.open(Time.now.to_i.to_s + '_large.CSV', 'wb') do |file|
my_bucket.objects.each do |obj|
file.write(my_bucket.objects[obj.key].read)
end
end
end
# count number of files
def self.upload
Dir['lib/extractor/temp/dataupload/*'].each do |item|
puts item
if item == '.' or item == '..'
# do not do anything with these
puts "starting"
else
Net::FTP.open('ftp.example.com', 'userftp', 'password') do |ftp|
ftp.passive = true
ftp.putbinaryfile(item)
File.delete(item)
end
end
end
end
end