class MovieMasher::Callback

A Transfer object and element in Job#callbacks representing a remote request triggered at a particular stage in processing.

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

The request body is always a JSON payload built from data by recursively evaluating all its String values. When a value contains curly brace pairs, the text they wrap is treated as a key path into a scope that contains the Job and Callback being triggered. For instance, {job.destination.type} might evaluate to 'http'. To reference 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

Returns a new instance.

# File lib/callback.rb, line 39
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 43
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 51
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 57
def data=(value)
  _set(__method__, value)
end
extension() click to toggle source
# File lib/callback.rb, line 61
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 66
def extension=(value)
  _set(__method__, value)
end
name() click to toggle source
# File lib/callback.rb, line 70
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 76
def name=(value)
  _set(__method__, value)
end
progress_seconds() click to toggle source
# File lib/callback.rb, line 80
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 87
def progress_seconds=(value)
  _set(__method__, value)
end
trigger() click to toggle source
# File lib/callback.rb, line 91
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 or Trigger::COMPLETE

Default

Trigger::COMPLETE

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