Class: BucketSyncService
- Inherits:
-
Object
- Object
- BucketSyncService
- Defined in:
- lib/aws_one_click_staging/bucket_sync_service.rb
Instance Attribute Summary collapse
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#from_bucket ⇒ Object
readonly
Returns the value of attribute from_bucket.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#to_bucket ⇒ Object
readonly
Returns the value of attribute to_bucket.
Instance Method Summary collapse
-
#initialize(from_credentials, to_credentials) ⇒ BucketSyncService
constructor
from_credentials and to_credentials are both hashes with these keys: * :aws_access_key_id * :aws_secret_access_key * :bucket.
- #perform(output = STDOUT) ⇒ Object
Constructor Details
#initialize(from_credentials, to_credentials) ⇒ BucketSyncService
from_credentials and to_credentials are both hashes with these keys:
* :aws_access_key_id
* :aws_secret_access_key
* :bucket
14 15 16 17 |
# File 'lib/aws_one_click_staging/bucket_sync_service.rb', line 14 def initialize(from_credentials, to_credentials) @from_bucket = get_bucket_reference(from_credentials) @to_bucket = get_bucket_reference(to_credentials) end |
Instance Attribute Details
#debug ⇒ Object
Returns the value of attribute debug.
8 9 10 |
# File 'lib/aws_one_click_staging/bucket_sync_service.rb', line 8 def debug @debug end |
#from_bucket ⇒ Object (readonly)
Returns the value of attribute from_bucket.
7 8 9 |
# File 'lib/aws_one_click_staging/bucket_sync_service.rb', line 7 def from_bucket @from_bucket end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
7 8 9 |
# File 'lib/aws_one_click_staging/bucket_sync_service.rb', line 7 def logger @logger end |
#to_bucket ⇒ Object (readonly)
Returns the value of attribute to_bucket.
7 8 9 |
# File 'lib/aws_one_click_staging/bucket_sync_service.rb', line 7 def to_bucket @to_bucket end |
Instance Method Details
#perform(output = STDOUT) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aws_one_click_staging/bucket_sync_service.rb', line 19 def perform(output=STDOUT) AWS.eager_autoload! # this makes threads even more happy object_counts = {sync:0, skip:0} create_logger(output) threads = [] logger.info "Starting sync." from_bucket.objects.each do |object| threads << Thread.new { if object_needs_syncing?(object) sync(object) object_counts[:sync] += 1 else logger.debug "Skipped #{pp object}" object_counts[:skip] += 1 end } sleep 0.01 while threads.select {|t| t.alive?}.count > 16 end ThreadsWait.all_waits(threads) logger.info "Done. Synced #{object_counts[:sync]}, " + "skipped #{object_counts[:skip]}." end |