Class: ElasticBeans::Exec::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_beans/exec/command.rb

Overview

A command enqueued or running on an exec instance in this Application, from beans exec.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_string:, freeze_instance: false, id: nil, instance_id: nil, start_time: nil, metadata: nil) ⇒ Command

Returns a new instance of Command.



24
25
26
27
28
29
30
31
# File 'lib/elastic_beans/exec/command.rb', line 24

def initialize(command_string:, freeze_instance: false, id: nil, instance_id: nil, start_time: nil, metadata: nil)
  @id = id || SecureRandom.uuid
  @command_string = command_string
  @freeze = freeze_instance
  @instance_id = instance_id
  @start_time = start_time
  @metadata =  || {}
end

Instance Attribute Details

#command_stringObject (readonly)

The command string that is executed; the string passed to beans exec



13
14
15
# File 'lib/elastic_beans/exec/command.rb', line 13

def command_string
  @command_string
end

#idObject (readonly)

A unique ID to identify this command later on.



10
11
12
# File 'lib/elastic_beans/exec/command.rb', line 10

def id
  @id
end

#instance_idObject

The instance ID this command is being executed on.



16
17
18
# File 'lib/elastic_beans/exec/command.rb', line 16

def instance_id
  @instance_id
end

#metadataObject (readonly)

Command metadata, such as where to store execution data in S3.



22
23
24
# File 'lib/elastic_beans/exec/command.rb', line 22

def 
  @metadata
end

#start_timeObject

The time this command started execution.



19
20
21
# File 'lib/elastic_beans/exec/command.rb', line 19

def start_time
  @start_time
end

Class Method Details

.freeze_instanceObject

A special ElasticBeans::Exec::Command that instructs the instance to not do anything. Used for interactive exec commands, like rails console.



67
68
69
# File 'lib/elastic_beans/exec/command.rb', line 67

def self.freeze_instance
  new(command_string: nil, freeze_instance: true)
end

.from_json(json) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/elastic_beans/exec/command.rb', line 53

def self.from_json(json)
  attributes = JSON.parse(json)
  new(
    id: attributes["id"],
    command_string: attributes["command"],
    freeze_instance: attributes["freeze"],
    instance_id: attributes["instance_id"],
    start_time: attributes["start_time"] ? Time.iso8601(attributes["start_time"]) : nil,
    metadata: attributes["metadata"],
  )
end

Instance Method Details

#==(other) ⇒ Object



33
34
35
# File 'lib/elastic_beans/exec/command.rb', line 33

def ==(other)
  id == other.id
end

#freeze_instance?Boolean

Instead of a command_string to execute, instruct the instance to not do anything.

Returns:

  • (Boolean)


38
39
40
# File 'lib/elastic_beans/exec/command.rb', line 38

def freeze_instance?
  @freeze
end

#to_jsonObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/elastic_beans/exec/command.rb', line 42

def to_json
  attributes = {}
  attributes[:id] = id
  attributes[:command] = command_string if command_string
  attributes[:freeze] = true if freeze_instance?
  attributes[:instance_id] = instance_id if instance_id
  attributes[:start_time] = start_time.iso8601 if start_time
  attributes[:metadata] = 
  attributes.to_json
end