Module: DropboxUtil
- Includes:
- LoggerUtil
- Defined in:
- lib/jenkins_util/dropbox_util.rb
Instance Attribute Summary collapse
-
#uploaded_files ⇒ Object
readonly
Returns the value of attribute uploaded_files.
Class Method Summary collapse
- .delete(file_path) ⇒ Object
- .download(file_path) ⇒ Object
- .retrier(file) ⇒ Object
- .upload(sources, destination, flatten = true, root = nil) ⇒ Object
Methods included from LoggerUtil
Instance Attribute Details
#uploaded_files ⇒ Object (readonly)
Returns the value of attribute uploaded_files.
9 10 11 |
# File 'lib/jenkins_util/dropbox_util.rb', line 9 def uploaded_files @uploaded_files end |
Class Method Details
.delete(file_path) ⇒ Object
27 28 29 |
# File 'lib/jenkins_util/dropbox_util.rb', line 27 def self.delete(file_path) retrier(file_path) { @dropbox_client.delete(file_path) } unless @dropbox_client.nil? end |
.download(file_path) ⇒ Object
79 80 81 |
# File 'lib/jenkins_util/dropbox_util.rb', line 79 def self.download(file_path) retrier(file_path) { @dropbox_client.download(file_path) } end |
.retrier(file) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/jenkins_util/dropbox_util.rb', line 83 def self.retrier(file) retries = 0 begin response = yield rescue DropboxApi::Errors::BasicError, DropboxApi::Errors::HttpError => e retries += 1 if retries <= 10 # Rate Limit and Namespace Lock Contentions introduced in v2 APIs # https://www.dropbox.com/developers/reference/data-ingress-guide delay = e.is_a?(DropboxApi::Errors::TooManyWriteOperationsError) ? e.retry_after * retries : retries sleep(delay) LoggerUtil.log.debug("Attempt #{retries} failed. Retrying #{file} after #{delay} seconds") retry end LoggerUtil.fatal("Exceeded maximum retries. Failed from #{caller_locations[0].label} method with file #{file}") raise e end response unless response.nil? end |
.upload(sources, destination, flatten = true, root = nil) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/jenkins_util/dropbox_util.rb', line 11 def self.upload(sources, destination, flatten = true, root = nil) LoggerUtil.fatal('Sources passed is nil') if sources.nil? LoggerUtil.fatal('Destination passed is nil') if destination.nil? LoggerUtil.fatal('Root must be passed if flatten is false') if !flatten && root.nil? LoggerUtil.fatal('Please set environment variable DROPBOX_ACCESS_TOKEN') if ENV['DROPBOX_ACCESS_TOKEN'].nil? @dropbox_client ||= DropboxApi::Client.new(ENV['DROPBOX_ACCESS_TOKEN']) @sources = sources @flatten = flatten @root_path = root || Dir.pwd @destination = destination @destination = "/#{@destination}" unless destination.to_s.start_with?('/') upload_files end |