Class: HotPotato::Route::AppTask

Inherits:
Object
  • Object
show all
Includes:
Core
Defined in:
lib/hot_potato/dsl.rb

Direct Known Subclasses

Faucet, Sink, Worker

Constant Summary

Constants included from Core

Core::CONFIG_PATH

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Core

#acquire_lock, #config, #log, #queue_inject, #queue_subscribe, #release_lock, #set_logger, #stat

Constructor Details

#initialize(classname, options = {}) ⇒ AppTask

Returns a new instance of AppTask.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/hot_potato/dsl.rb', line 119

def initialize(classname, options = {})
  @classname = classname.to_s
  @instances = options[:instances] || 1
  @group     = options[:group] || ""
  if options[:source]
    if options[:source].class == Array
      @source = options[:source].map { |s| s.to_s }
    else
      @source = [options[:source].to_s]
    end
  else
    @source = nil
  end
end

Instance Attribute Details

#classnameObject

Returns the value of attribute classname.



118
119
120
# File 'lib/hot_potato/dsl.rb', line 118

def classname
  @classname
end

#groupObject

Returns the value of attribute group.



118
119
120
# File 'lib/hot_potato/dsl.rb', line 118

def group
  @group
end

#instancesObject

Returns the value of attribute instances.



118
119
120
# File 'lib/hot_potato/dsl.rb', line 118

def instances
  @instances
end

#sourceObject

Returns the value of attribute source.



118
119
120
# File 'lib/hot_potato/dsl.rb', line 118

def source
  @source
end

Instance Method Details

#allow_group(name) ⇒ Object



134
135
136
137
# File 'lib/hot_potato/dsl.rb', line 134

def allow_group(name)
  return true if @group == ""
  return name == @group.to_s
end

#running_instancesObject



139
140
141
# File 'lib/hot_potato/dsl.rb', line 139

def running_instances
  stat.keys("hotpotato.apptask.*.#{classify(@classname)}.*").count || 0
end

#typeObject



143
144
145
146
147
148
# File 'lib/hot_potato/dsl.rb', line 143

def type
  return "Faucet" if Kernel.const_get(@data[:classname]).ancestors.include?(HotPotato::Faucet)
  return "Worker" if Kernel.const_get(@data[:classname]).ancestors.include?(HotPotato::Worker)
  return "Sink"   if Kernel.const_get(@data[:classname]).ancestors.include?(HotPotato::Sink)  
  return "AppTask"  
end