lib/dbox/syncer.rb in dbox-0.6.13 vs lib/dbox/syncer.rb in dbox-0.6.14

- old
+ new

@@ -1,8 +1,8 @@ module Dbox class Syncer - MAX_PARALLEL_DBOX_OPS = 3 + DEFAULT_CONCURRENCY = 2 MIN_BYTES_TO_STREAM_DOWNLOAD = 1024 * 100 # 100kB include Loggable def self.create(remote_path, local_path) @@ -34,10 +34,15 @@ def self.api @@_api ||= API.connect end + def self.concurrency + n = ENV["DROPBOX_CONCURRENCY"].to_i + n > 0 ? n : DEFAULT_CONCURRENCY + end + class Operation include Loggable include Utils attr_reader :database @@ -182,11 +187,11 @@ log.debug "Executing changes:\n" + changes.map {|c| c.inspect }.join("\n") parent_ids_of_failed_entries = [] changelist = { :created => [], :deleted => [], :updated => [], :failed => [] } # spin up a parallel task queue - ptasks = ParallelTasks.new(MAX_PARALLEL_DBOX_OPS - 1) { clone_api_into_current_thread() } + ptasks = ParallelTasks.new(Syncer.concurrency) { clone_api_into_current_thread() } ptasks.start changes.each do |op, c| case op when :create @@ -443,10 +448,10 @@ changes = calculate_changes(dir) log.debug "Executing changes:\n" + changes.map {|c| c.inspect }.join("\n") changelist = { :created => [], :deleted => [], :updated => [], :failed => [] } # spin up a parallel task queue - ptasks = ParallelTasks.new(MAX_PARALLEL_DBOX_OPS - 1) { clone_api_into_current_thread() } + ptasks = ParallelTasks.new(Syncer.concurrency) { clone_api_into_current_thread() } ptasks.start changes.each do |op, c| case op when :create