class EXEL::Context

The Context is the shared memory of a running job. It acts as the source of input to processors and the place for them to store their outputs. It can be serialized and deserialized to support remote execution.

Public Class Methods

deserialize(uri) click to toggle source

Given a string representing the URI to a serialized context, downloads and returns the deserialized context

@return [Context]

# File lib/exel/context.rb, line 34
def self.deserialize(uri)
  file = EXEL::Value.localize(uri)

  begin
    context = Marshal.load(file.read) # rubocop:disable Airbnb/UnsafeYamlMarshal
  ensure
    file.close
  end

  context
end
new(initial_context = {}) click to toggle source

Accepts an optional hash of keys and values to initialize the context with.

Calls superclass method
# File lib/exel/context.rb, line 11
def initialize(initial_context = {})
  super()
  merge!(initial_context)
end

Public Instance Methods

[](key) click to toggle source

Returns the value referenced by the given key. If it is a remote value, it will be converted to a local value and the local value will be returned.

Calls superclass method
# File lib/exel/context.rb, line 48
def [](key)
  convert_value!(key, super(key))
end
deep_dup() click to toggle source

Returns a deep copy of this context. The copy and the original will have no shared object references.

@return [Context]

# File lib/exel/context.rb, line 19
def deep_dup
  Context.deserialize(serialize)
end
fetch(key) click to toggle source
Calls superclass method
# File lib/exel/context.rb, line 52
def fetch(key)
  convert_value!(key, super(key))
end
serialize() click to toggle source

Serializes this instance to a local file and uses the remote provider to upload it. Returns a URI indicating where the serialized context can be downloaded.

@return [String] A URI such as s3://bucket/file, file:///path/to/file, etc.

# File lib/exel/context.rb, line 27
def serialize
  EXEL::Value.remotize(serialized_context)
end

Private Instance Methods

convert_value!(key, value) click to toggle source
# File lib/exel/context.rb, line 69
def convert_value!(key, value)
  value = EXEL::Value.localize(value)
  value = DeferredContextValue.resolve(value, self)
  self[key] = value
end
remotized_table() click to toggle source
# File lib/exel/context.rb, line 65
def remotized_table
  each_with_object({}) { |(key, value), acc| acc[key] = EXEL::Value.remotize(value) }
end
serialized_context() click to toggle source
# File lib/exel/context.rb, line 58
def serialized_context
  file = Tempfile.new(SecureRandom.uuid, encoding: 'ascii-8bit')
  file.write(Marshal.dump(Context.new(remotized_table)))
  file.rewind
  file
end