Class: X::MediaProcessingTimeout

Inherits:
Uploader::Error show all
Defined in:
x-uploader/lib/x/uploader/media_processing_timeout.rb

Overview

Error raised when uploaded media is still processing after the time await_processing may wait

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, media: nil, timeout: nil) ⇒ MediaProcessingTimeout

Initialize the error with the last status and the time that was allowed

The message is the one given, or else names the time that was allowed, when one was given.

Examples:

Raise the error after ten minutes

raise X::MediaProcessingTimeout.new(media: status, timeout: 600)

Raise the error with a message of its own, as a test stub may

raise X::MediaProcessingTimeout, "Still processing"

Parameters:

  • message (String, nil) (defaults to: nil) —

    the message, or nil for one that names the time allowed

  • media (UploadedMedia, Hash{String => Object}, nil) (defaults to: nil) —

    the media, as the last processing status X reported describes it, a Hash of which is held as uploaded media

  • timeout (Integer, Float, nil) (defaults to: nil) —

    the seconds await_processing was allowed to wait



49
50
51
52
53
# File 'x-uploader/lib/x/uploader/media_processing_timeout.rb', line 49

def initialize(message = nil, media: nil, timeout: nil)
  @media = media.is_a?(Hash) ? UploadedMedia.new(media) : media
  @timeout = timeout
  super(message || (timeout ? format(WITHIN_TIMEOUT, timeout) : "Media processing did not finish"))
end

Instance Attribute Details

#media ⇒ UploadedMedia? (readonly)

The uploaded media, as the last processing status X reported describes it

Its processing_info holds the state and progress of the processing.

Examples:

Read how far processing got

error.media.dig("processing_info", "progress_percent") # => 42

Wait for the media again later

rescue X::MediaProcessingTimeout => e
  client.await_media_processing(e.media)

Returns:

  • (UploadedMedia, nil) —

    the media, which reads as a Hash, or nil if none was given



26
27
28
# File 'x-uploader/lib/x/uploader/media_processing_timeout.rb', line 26

def media
  @media
end

#timeout ⇒ Integer, ... (readonly)

The seconds await_processing was allowed to wait

Examples:

Read how long processing was awaited

error.timeout # => 600

Returns:

  • (Integer, Float, nil) —

    the seconds, or nil if none were given



33
34
35
# File 'x-uploader/lib/x/uploader/media_processing_timeout.rb', line 33

def timeout
  @timeout
end