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.


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

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:


34
35
36
37
38
39
40
41
42
43
44
# 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

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.


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

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:


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

def deep_dup
  Context.deserialize(serialize)
end

#fetch(key) ⇒ Object


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

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.


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

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