Class: EXEL::Context

Inherits:
Hash
  • Object
show all
Defined in:
lib/exel/context.rb

Overview

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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(initial_context = {}) ⇒ Context

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



10
11
12
13
# File 'lib/exel/context.rb', line 10

def initialize(initial_context = {})
  super()
  merge!(initial_context)
end

Class Method Details

.deserialize(uri) ⇒ Context

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

Returns:



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/exel/context.rb', line 33

def self.deserialize(uri)
  file = EXEL::Value.localize(uri)

  begin
    context = Marshal.load(file.read)
  ensure
    file.close
  end

  context
end

Instance Method Details

#[](key) ⇒ Object

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.



47
48
49
# File 'lib/exel/context.rb', line 47

def [](key)
  convert_value!(key, super(key))
end

#deep_dupContext

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

Returns:



18
19
20
# File 'lib/exel/context.rb', line 18

def deep_dup
  Context.deserialize(serialize)
end

#fetch(key) ⇒ Object



51
52
53
# File 'lib/exel/context.rb', line 51

def fetch(key)
  convert_value!(key, super(key))
end

#serializeString

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.

Returns:

  • (String)

    A URI such as s3://bucket/file, file:///path/to/file, etc.



26
27
28
# File 'lib/exel/context.rb', line 26

def serialize
  EXEL::Value.remotize(serialized_context)
end