Class: Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/processor/processor.rb

Overview

A Processor is a link in the processing chain. This is where

the processor gets chosen and the application runs on top of 
the chosen processor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket, hostname = Processor.get_current_hostname) ⇒ Processor

Returns a new instance of Processor.



40
41
42
43
# File 'lib/processor/processor.rb', line 40

def initialize(bucket, hostname = Processor.get_current_hostname)
  @bucket = bucket
  @hostname = hostname
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



38
39
40
# File 'lib/processor/processor.rb', line 38

def bucket
  @bucket
end

#hostnameObject (readonly)

Returns the value of attribute hostname.



38
39
40
# File 'lib/processor/processor.rb', line 38

def hostname
  @hostname
end

Class Method Details

.get_current_hostnameObject

return the current unix hostname



77
78
79
# File 'lib/processor/processor.rb', line 77

def self.get_current_hostname
  return `hostname`.chomp
end

Instance Method Details

#==(other) ⇒ Object

equality operator



67
68
69
# File 'lib/processor/processor.rb', line 67

def ==(other)
  return @hostname == other.hostname
end

#active?Boolean

is this processor working?

Returns:

  • (Boolean)


61
62
63
64
# File 'lib/processor/processor.rb', line 61

def active?
  # check to see if this server is pingable
  return Net::PingExternal.new(@hostname).ping
end

#not_equal?(other) ⇒ Boolean

inequality operator

Returns:

  • (Boolean)


72
73
74
# File 'lib/processor/processor.rb', line 72

def not_equal?(other)
  return @hostname != other.hostname
end

#registerObject

make this processor available to the pool



46
47
48
# File 'lib/processor/processor.rb', line 46

def register
  AWS::S3::S3Object.store(@hostname, 'ready', @bucket) if @hostname && @bucket
end

#registered?Boolean

check to see if this processor has been properly registered

Returns:

  • (Boolean)


56
57
58
# File 'lib/processor/processor.rb', line 56

def registered?
  AWS::S3::S3Object.exists?(@hostname, @bucket)
end

#unregisterObject

remove this processor from the pool



51
52
53
# File 'lib/processor/processor.rb', line 51

def unregister
  AWS::S3::S3Object.delete(@hostname, @bucket) if @hostname && @bucket
end

#url_forObject

return the URL needed to try to upload to this processor



82
83
84
# File 'lib/processor/processor.rb', line 82

def url_for
  "http://#{@hostname}:4567/new"
end