title: Carrierwave and delayed_job uploading single file two times in the upload directory
body: <p>I trying to upload large file (upto 2 gb) from my sample app. I am using <strong>carrierwave gem</strong> for file uploading</p>
  
  <p>While uploading files it is taking too much time and also it is allocating server process while uploading. After searching I get this <a href="https://stackoverflow.com/questions/18342385/ror-large-file-uploads-in-rails">link</a>. So I tried to use <strong>delayed job</strong> for background process.</p>
  
  <p>For using combine carrierwave and delayed job I followed this <a href="http://www.freezzo.com/2011/01/06/how-to-use-delayed-job-to-handle-your-carrierwave-processing/" rel="nofollow noreferrer">tutorial</a>.
  I performed all steps as mentioned in the tutorial. File is uploading successfully.</p>
  
  <p>But after I looked into the uploaded directory I get that file is uploading twice with different names example - bitrate_128k_IMG_5099.MOV and IMG_5099.MOV</p>
  
  <p>I tried to debug it but I didn't get any solution for it.</p>
  
  <p><strong>video.rb</strong></p>
  
  <pre><code>class Video &lt; ActiveRecord::Base  
    mount_uploader :video, VideoUploader  
    after_save :enqueue  
  end
  </code></pre>
  
  <p><strong>videos_controller.rb</strong></p>
  
  <pre><code>class VideosController &lt; ApplicationController    
    def index
    end
  
    def show
      @video = Video.find(params[:id])
    end
  
    def new
      @video = Video.new(video_params)    
    end
  
    def create    
      @video = Video.new(video_params)    
      if @video.save
        redirect_to @video
      else
        render :nothing =&gt; true, :status =&gt; 400
      end
    end
  
    private
    def video_params
      params.require(:video).permit(:attachment, :zencoder_output_id, :processed, :video, :meta_info, :processing) if params[:video]
    end 
  end
  </code></pre>
  
  <p><strong>/uploader/video_uploader.rb</strong></p>
  
  <pre><code># encoding: utf-8
  require File.join(Rails.root, "lib", "carrier_wave", "ffmpeg") 
  require File.join(Rails.root, "lib", "carrier_wave", "delayed_job")
  
  class VideoUploader &lt; CarrierWave::Uploader::Base
  
    include CarrierWave::Delayed::Job 
    include CarrierWave::FFMPEG 
  
    storage :file
  
    def store_dir
      "videos/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
    end
  
    version :bitrate_128k do 
      process :resample =&gt; "128k" 
    end
  
    def extension_white_list
      %w(avi mov mkv mpg mpeg mp4 m4v flv ogv)
    end  
  end
  </code></pre>
  
  <p><strong>lib/carrier_wave/delayed_job.rb</strong></p>
  
  <pre><code># lib/carrier_wave/delayed_job.rb
  module CarrierWave
    module Delayed
      module Job
        module ActiveRecordInterface
          def delay_carrierwave
            @delay_carrierwave ||= true
          end
  
          def delay_carrierwave=(delay)
            @delay_carrierwave = delay
          end
  
          def perform
            asset_name = self.class.uploader_options.keys.first
            self.send(asset_name).versions.each_pair do |key, value|
              value.process_without_delay!
            end
          end
  
          private
          def enqueue
            ::Delayed::Job.enqueue self
          end
        end
  
        def self.included(base)
          base.extend ClassMethods
        end
  
        module ClassMethods
          def self.extended(base)
            base.send(:include, InstanceMethods)
            base.alias_method_chain :process!, :delay
            ::ActiveRecord::Base.send(:include, CarrierWave::Delayed::Job::ActiveRecordInterface)
          end
  
          module InstanceMethods
            def process_with_delay!(new_file)
              process_without_delay!(new_file) unless model.delay_carrierwave
            end
          end
        end
      end
    end
  end
  </code></pre>
  
  <p><strong>controller/videos/new.html.erb</strong></p>
  
  <pre><code>&lt;h2&gt;Upload your Video&lt;/h2&gt;
  
  &lt;%= form_for @video, :html =&gt; {:multipart =&gt; true} do |f| %&gt;  
    &lt;p&gt;
      &lt;%= f.label :attachment %&gt;&lt;br /&gt;
      &lt;%= f.text_field :attachment %&gt;
    &lt;/p&gt;
    &lt;p&gt;
      &lt;%= f.file_field :video %&gt;
    &lt;/p&gt;
    &lt;p&gt;&lt;%= f.submit %&gt;&lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>How can I stop this two times recording.
  I am using rails 4 for this.</p>