microspino
microspino

Reputation: 7781

Rails3 deferred ftp upload

I need a way to implement deferred FTP uploads, to different servers, in a Rails3 application. This will be the scenario:

  1. The user builds a folder full of files and subfolders, with a simple Rails3 CMS (DONE)
  2. When the user ends his work, he would click on a deploy button.
  3. The system takes the control and stores the user request.
  4. The systen gives the control back to the user, this way he can work on other stuff.
  5. At the same time the system initiates 10 FTP uploads of the same folder.
  6. When an upload ends it will store its status somewhere.
  7. The user can see the deployment status, at any time, by going on a specific page.

Uploaded folders size will be from 600Mb to 1Gb. They will contain PNG images, little mp4 movies and xml files.

The web server and all the ftp server will be on the same network, same subnet. No need of extra security for now. I'm completely new to asynchronous or delayed jobs. The application will have just one or two users: no need to handle a lot of deploy requests at the same time.

How can I accomplish this task? If you need more info please ask in the comments.

Upvotes: 0

Views: 354

Answers (1)

natedavisolds
natedavisolds

Reputation: 4295

Once you have delayed_job set up, you can set a method to perform in the background while you go about your business. In this case, the deploy method would always be in the background–set by handle_asynchronously.

class UploadStatus < ActiveRecord::Base

  def deploy
     # write your ftp loop here
     # periodically update this model in the db with the status
  end
  handle_asynchronously :deploy

end

Now, you can just call @upload_status.deploy() and it will run in the background.

You could also write a job method, but I think that it makes more sense in an ActiveRecord class because you will be updating the deploy status.

Upvotes: 1

Related Questions