Class: TelestreamCloud::Qc::Uploader
- Inherits:
-
Object
- Object
- TelestreamCloud::Qc::Uploader
- Defined in:
- lib/telestream_cloud_qc/uploader.rb
Defined Under Namespace
Classes: ConcurrentFileUploadSession, FileReader, FileUploadSession, MissingPartError, UploadError
Instance Attribute Summary collapse
-
#concurrency ⇒ Object
readonly
Returns the value of attribute concurrency.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#thread_pool ⇒ Object
readonly
Returns the value of attribute thread_pool.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(client, options) ⇒ Uploader
constructor
A new instance of Uploader.
- #parse_extra_files(extra_files) ⇒ Object
- #success? ⇒ Boolean
- #upload(retries = 5) ⇒ Object
- #upload_session(path, tag = nil) ⇒ Object
Constructor Details
#initialize(client, options) ⇒ Uploader
Returns a new instance of Uploader.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/telestream_cloud_qc/uploader.rb', line 154 def initialize(client, ) @client = client @thread_pool = Concurrent::ThreadPoolExecutor.new( min_threads: 5, max_threads: 5, max_queue: 100, fallback_policy: :caller_runs ) file = .delete(:file) do |key| raise KeyError, "key not found: #{key}" end @extra_files = parse_extra_files(.delete(:extra_files)) @upload_session = upload_session(file) defaults = { multi_chunk: true }.merge(@upload_session.params) @params = defaults.merge() @params[:extra_files] = @extra_files.map(&:params) if @extra_files @status = :ready end |
Instance Attribute Details
#concurrency ⇒ Object (readonly)
Returns the value of attribute concurrency.
147 148 149 |
# File 'lib/telestream_cloud_qc/uploader.rb', line 147 def concurrency @concurrency end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
147 148 149 |
# File 'lib/telestream_cloud_qc/uploader.rb', line 147 def error @error end |
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
147 148 149 |
# File 'lib/telestream_cloud_qc/uploader.rb', line 147 def reader @reader end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
147 148 149 |
# File 'lib/telestream_cloud_qc/uploader.rb', line 147 def status @status end |
#thread_pool ⇒ Object (readonly)
Returns the value of attribute thread_pool.
147 148 149 |
# File 'lib/telestream_cloud_qc/uploader.rb', line 147 def thread_pool @thread_pool end |
Class Method Details
.upload(options) ⇒ Object
149 150 151 152 |
# File 'lib/telestream_cloud_qc/uploader.rb', line 149 def self.upload() retries = .delete(:retries) new().tap { |x| x.upload(*[retries].compact) }.video end |
Instance Method Details
#parse_extra_files(extra_files) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/telestream_cloud_qc/uploader.rb', line 183 def parse_extra_files(extra_files) return [] unless extra_files extra_files.flat_map do |tag, paths| paths = [paths] unless paths.kind_of?(Array) paths.each_with_index.map do |path, i| upload_session(path, paths.size > 1 ? "#{tag}.index-#{i}" : tag) end end end |
#success? ⇒ Boolean
212 213 214 |
# File 'lib/telestream_cloud_qc/uploader.rb', line 212 def success? @resource_id && @upload_session.success? && Array(@extra_files).all?(&:success?) end |
#upload(retries = 5) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/telestream_cloud_qc/uploader.rb', line 195 def upload(retries = 5) session count = 0 begin count += 1 upload! raise MissingPartError unless success? rescue StandardError => e puts e @error = e retry if count < retries end @resource_id end |
#upload_session(path, tag = nil) ⇒ Object
216 217 218 |
# File 'lib/telestream_cloud_qc/uploader.rb', line 216 def upload_session(path, tag = nil) ConcurrentFileUploadSession.new(self, path, tag) end |