class MovieMasher::Callback

A Transfer object and element in MovieMasher::Job#callbacks representing a remoterequest triggered at a particular stage in processing.

There are four types of trigger events for callbacks -Trigger::INITIATE, Trigger::PROGRESS, Trigger::ERROR andTrigger::COMPLETE. After MovieMasher::Job#process is called, allTrigger::INITIATE callbacks are requested. Then, every#progress_seconds or so, each Trigger::PROGRESS callback isrequested. If a problem is encountered while downloading orrendering/uploading a required Output then all TriggereErrorcallbacks are requested. And finally, all Trigger::COMPLETEcallbacks are requested.

The request body is always a JSON payload built from data byrecursively evaluating all its String values. When a value containscurly brace pairs, the text they wrap is treated as a key path intoa scope that contains the Job and Callback being triggered. Forinstance, {job.destination.type} might evaluate to 'http'. Toreference an Array element use a zero-based index in the key path,like {job.inputs.0.type} which might evaluate to 'audio'.

Callback.create {
  type: Type::HTTP,
  trigger: Trigger::ERROR, # request only if error encountered
  host: 'example.com',     # http://example.com/cgi-bin/error.cgi?i=123
  path: 'cgi-bin/error.cgi',
  parameters: {i: '{job.id}'},   # Scalar - Job#id
  data: {                        # body of request, JSON formatted
    log: '{job.log}',            # String - Job#log
    error: '{job.error}',        # String - Job#error
    progress: '{job.progress}'   # Hash - Job#progress
  }
}

Public Class Methods

create(hash = nil) click to toggle source

Returns a new instance.

# File lib/callback.rb, line 38
def self.create(hash = nil)
  (hash.is_a?(Callback) ? hash : Callback.new(hash))
end
init_hash(hash) click to toggle source
# File lib/callback.rb, line 41
def self.init_hash(hash)
  Hashable._init_key(hash, :trigger, Trigger::COMPLETE)
  if Trigger::PROGRESS == hash[:trigger]
    Hashable._init_key(hash, :progress_seconds, 10)
  end
  Transfer.init_hash(hash)
end

Public Instance Methods

data() click to toggle source
# File lib/callback.rb, line 48
def data
  _get(__method__)
end
data=(value) click to toggle source

Hash/Array - Values to recursively evaluate and parse into request body.

Default

nil

# File lib/callback.rb, line 53
def data=(value)
  _set(__method__, value)
end
extension() click to toggle source
# File lib/callback.rb, line 56
def extension
  _get(__method__)
end
extension=(value) click to toggle source
String

Added to file path after name, with period inserted between.

# File lib/callback.rb, line 60
def extension=(value)
  _set(__method__, value)
end
name() click to toggle source
# File lib/callback.rb, line 63
def name
  _get(__method__)
end
name=(value) click to toggle source
String

The full or basename of file added to URL after path. If full,#extension will be set and removed from value.

# File lib/callback.rb, line 68
def name=(value)
  _set(__method__, value)
end
progress_seconds() click to toggle source
# File lib/callback.rb, line 71
def progress_seconds
  _get(__method__)
end
progress_seconds=(value) click to toggle source
Integer

Seconds to wait before making requests.

Default

44100

Triggers

Only Trigger::PROGRESS.

# File lib/callback.rb, line 77
def progress_seconds=(value)
  _set(__method__, value)
end
trigger() click to toggle source
# File lib/callback.rb, line 80
def trigger
  _get(__method__)
end
trigger=(value) click to toggle source
String

The event that fires the request.

Constant

Trigger::INITIATE, Trigger::PROGRESS, Trigger::ERROR orTrigger::COMPLETE

Default

Trigger::COMPLETE

# File lib/callback.rb, line 87
def trigger=(value)
  _set(__method__, value)
end