Class: SimpleMapReduce::Server::Task

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
AASM
Defined in:
lib/simple_map_reduce/server/task.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, job_id:, task_class_name:, task_script:, task_input_bucket_name:, task_input_file_path:, task_output_bucket_name:, task_output_directory_path:, worker: nil) ⇒ Task

Returns a new instance of Task.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/simple_map_reduce/server/task.rb', line 40

def initialize(id: nil,
               job_id:,
               task_class_name:,
               task_script:,
               task_input_bucket_name:,
               task_input_file_path:,
               task_output_bucket_name:,
               task_output_directory_path:,
               worker: nil)
  @id = id
  @job_id = job_id
  @task_class_name = task_class_name
  @task_script = task_script
  @task_input_bucket_name = task_input_bucket_name
  @task_input_file_path = task_input_file_path
  @task_output_bucket_name = task_output_bucket_name
  @task_output_directory_path = task_output_directory_path
  @worker = worker
end

Instance Attribute Details

#job_idObject (readonly)

Returns the value of attribute job_id.



12
13
14
# File 'lib/simple_map_reduce/server/task.rb', line 12

def job_id
  @job_id
end

#task_class_nameObject (readonly)

Returns the value of attribute task_class_name.



12
13
14
# File 'lib/simple_map_reduce/server/task.rb', line 12

def task_class_name
  @task_class_name
end

#task_input_bucket_nameObject (readonly)

Returns the value of attribute task_input_bucket_name.



12
13
14
# File 'lib/simple_map_reduce/server/task.rb', line 12

def task_input_bucket_name
  @task_input_bucket_name
end

#task_input_file_pathObject (readonly)

Returns the value of attribute task_input_file_path.



12
13
14
# File 'lib/simple_map_reduce/server/task.rb', line 12

def task_input_file_path
  @task_input_file_path
end

#task_output_bucket_nameObject (readonly)

Returns the value of attribute task_output_bucket_name.



12
13
14
# File 'lib/simple_map_reduce/server/task.rb', line 12

def task_output_bucket_name
  @task_output_bucket_name
end

#task_output_directory_pathObject (readonly)

Returns the value of attribute task_output_directory_path.



12
13
14
# File 'lib/simple_map_reduce/server/task.rb', line 12

def task_output_directory_path
  @task_output_directory_path
end

#task_scriptObject (readonly)

Returns the value of attribute task_script.



12
13
14
# File 'lib/simple_map_reduce/server/task.rb', line 12

def task_script
  @task_script
end

#workerObject (readonly)

Returns the value of attribute worker.



12
13
14
# File 'lib/simple_map_reduce/server/task.rb', line 12

def worker
  @worker
end

Class Method Details

.deserialize(data) ⇒ Object



86
87
88
# File 'lib/simple_map_reduce/server/task.rb', line 86

def deserialize(data)
  new(Hash[MessagePack.unpack(data).map { |k, v| [k.to_sym, v] }])
end

Instance Method Details

#dumpObject



81
82
83
# File 'lib/simple_map_reduce/server/task.rb', line 81

def dump
  to_h.merge(state: state)
end

#idObject



60
61
62
# File 'lib/simple_map_reduce/server/task.rb', line 60

def id
  @id ||= SecureRandom.uuid
end

#serializeObject



77
78
79
# File 'lib/simple_map_reduce/server/task.rb', line 77

def serialize
  to_h.to_msgpack
end

#to_hObject



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/simple_map_reduce/server/task.rb', line 64

def to_h
  {
    id: id,
    job_id: @job_id,
    task_class_name: @task_class_name,
    task_script: @task_script,
    task_input_bucket_name: @task_input_bucket_name,
    task_input_file_path: @task_input_file_path,
    task_output_bucket_name: @task_output_bucket_name,
    task_output_directory_path: @task_output_directory_path
  }
end