Sha256: 083b0902f5a2dd97b2f8ef21fe14009d0f726821d4ddd59df5ae3c9f7e9e871a

Contents?: true

Size: 820 Bytes

Versions: 77

Compression:

Stored size: 820 Bytes

Contents

#!/usr/bin/env ruby

# You might want to change this
ENV["RAILS_ENV"] ||= "production"

require File.dirname(__FILE__) + "/../../config/environment"

$running = true
Signal.trap("TERM") do 
  $running = false
end

# Waiting is a timer variable to allow the daemon to restart
# within two seconds of the Signal rather than using a long
# sleep command and forcing the daemon to wait.
$waiting = 0

ActiveRecord::Base.logger.info "[AmazonS3] Migration daemon started at #{Time.now}.\n"

while($running) do

  if $waiting < 120
    $waiting += 2
    sleep 2
  else
    $waiting = 0
    upload = Upload.pending_s3_migration.first

    if upload
      $waiting = 120 - 2
      ActiveRecord::Base.logger.info "[AmazonS3] Migrating upload ##{upload.id}\n"
      upload.remote = upload.local
      upload.save!
    end
  end
end

Version data entries

77 entries across 68 versions & 5 rubygems

Version Path
uploader-0.2.1 lib/daemons/amazonaws.rb
uploader-0.2.1 test/rails_root/lib/daemons/amazonaws.rb
uploader-0.2.0 lib/daemons/amazonaws.rb
uploader-0.2.0 test/rails_root/lib/daemons/amazonaws.rb
uploader-0.1.19 lib/daemons/amazonaws.rb
uploader-0.1.20 lib/daemons/amazonaws.rb
uploader-0.1.16 lib/daemons/amazonaws.rb
uploader-0.1.17 lib/daemons/amazonaws.rb
uploader-0.1.18 lib/daemons/amazonaws.rb
uploader-0.1.12 lib/daemons/amazonaws.rb
uploader-0.1.13 lib/daemons/amazonaws.rb
uploader-0.1.14 lib/daemons/amazonaws.rb
uploader-0.1.10 lib/daemons/amazonaws.rb
uploader-0.1.15 lib/daemons/amazonaws.rb
uploader-0.1.8 lib/daemons/amazonaws.rb
uploader-0.1.9 lib/daemons/amazonaws.rb
uploader-0.1.7 lib/daemons/amazonaws.rb