This may be more of a Ruby question but I’m using Ruby on Rails so I
thought I would post it here.
Hopefully someone can provide a suggestion on how to approach this.
I have a method that uploads a selection of files via FTP. For each file
the method gets the file’s associated ftp host/domain, user name and
password, connects, uploads the file, updates the status of the file and
saves the updated information.
I’m now setting up error handling to email the file owner if the
response_code is not the expected successful code.
If a file has incorrect ftp information associated with it, I want to
send an email to the file owner to notify them, shouldn’t be a problem.
So, if there is incorrect connection info, Net::FTP will retry
connecting until it times out which could be 3 to 5 minutes or more
depending on the FTP server’s configuration.
I want to keep track of elapsed time and if the connection is not
established within 30 seconds, I want to cancel the connection and send
an email about the error to the file owner and move on to the next file.
So basically I want to make my own timeout, which times out faster than
the external FTP server.
start_timer_if_elapsed_time>=_30_seconds_cancel_connection #open ftp connection Net::FTP.open(ftp_link, ftp_username, ftp_password) # <-- this line shouldn't attempt to connect longer than 30 seconds do |ftp| ## send the file to the ftp ## update the status ## save the file end
Any suggestions appreciated