Class: DruidConfig::Entities::Worker
- Inherits:
-
Object
- Object
- DruidConfig::Entities::Worker
- Defined in:
- lib/druid_config/entities/worker.rb
Overview
Worker class
Instance Attribute Summary collapse
-
#capacity ⇒ Object
readonly
Readers.
-
#capacity_used ⇒ Object
(also: #used)
readonly
Readers.
-
#host ⇒ Object
readonly
Readers.
-
#ip ⇒ Object
readonly
Readers.
-
#last_completed_task_time ⇒ Object
readonly
Readers.
-
#port ⇒ Object
readonly
Readers.
-
#running_tasks ⇒ Object
readonly
Readers.
-
#version ⇒ Object
readonly
Readers.
Instance Method Summary collapse
-
#free ⇒ Object
Return free capacity.
-
#initialize(metadata) ⇒ Worker
constructor
Initialize it with received info.
-
#uri ⇒ Object
Return the uri of the worker.
-
#used_percent ⇒ Object
Return capacity used.
Constructor Details
#initialize(metadata) ⇒ Worker
Initialize it with received info
Parameters:
- metadata
-
Hash with returned metadata from Druid
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/druid_config/entities/worker.rb', line 18 def initialize() @host, @port = ['worker']['host'].split(':') @ip = ['worker']['ip'] @capacity = ['worker']['capacity'] @version = ['worker']['version'] @last_completed_task_time = ['lastCompletedTaskTime'] @running_tasks = ['runningTasks'].map do |task| DruidConfig::Entities::Task.new( task, DruidConfig::Entities::Task::STATUS[:running], created_time: task['createdTime'], query_insertion_time: task['queueInsertionTime']) end @capacity_used = ['currCapacityUsed'] end |
Instance Attribute Details
#capacity ⇒ Object (readonly)
Readers
8 9 10 |
# File 'lib/druid_config/entities/worker.rb', line 8 def capacity @capacity end |
#capacity_used ⇒ Object (readonly) Also known as: used
Readers
8 9 10 |
# File 'lib/druid_config/entities/worker.rb', line 8 def capacity_used @capacity_used end |
#host ⇒ Object (readonly)
Readers
8 9 10 |
# File 'lib/druid_config/entities/worker.rb', line 8 def host @host end |
#ip ⇒ Object (readonly)
Readers
8 9 10 |
# File 'lib/druid_config/entities/worker.rb', line 8 def ip @ip end |
#last_completed_task_time ⇒ Object (readonly)
Readers
8 9 10 |
# File 'lib/druid_config/entities/worker.rb', line 8 def last_completed_task_time @last_completed_task_time end |
#port ⇒ Object (readonly)
Readers
8 9 10 |
# File 'lib/druid_config/entities/worker.rb', line 8 def port @port end |
#running_tasks ⇒ Object (readonly)
Readers
8 9 10 |
# File 'lib/druid_config/entities/worker.rb', line 8 def running_tasks @running_tasks end |
#version ⇒ Object (readonly)
Readers
8 9 10 |
# File 'lib/druid_config/entities/worker.rb', line 8 def version @version end |
Instance Method Details
#free ⇒ Object
Return free capacity
39 40 41 42 |
# File 'lib/druid_config/entities/worker.rb', line 39 def free return @free if @free @free = (capacity - capacity_used) > 0 ? (capacity - capacity_used) : 0 end |
#uri ⇒ Object
Return the uri of the worker
55 56 57 |
# File 'lib/druid_config/entities/worker.rb', line 55 def uri "#{@host}:#{@port}" end |
#used_percent ⇒ Object
Return capacity used
47 48 49 50 |
# File 'lib/druid_config/entities/worker.rb', line 47 def used_percent return 0 unless @capacity && @capacity != 0 ((@capacity_used.to_f / @capacity) * 100).round(2) end |