Class: AutomateEm::ResolverJob

Inherits:
Object
  • Object
show all
Includes:
EM::Deferrable
Defined in:
lib/automate-em/core/resolver_pool.rb

Instance Method Summary collapse

Constructor Details

#initialize(hostname) ⇒ ResolverJob

Returns a new instance of ResolverJob.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/automate-em/core/resolver_pool.rb', line 42

def initialize(hostname)
	if IPAddress.valid? hostname
		self.succeed(hostname)
	else
		@hostname = hostname
		
		#
		# Enter self into resolver queue
		#
		if EM.reactor_thread?
			EM.defer do
				AutomateEm.resolver.schedule(self)
			end
		else
			AutomateEm.resolver.schedule(self)
		end
	end
end

Instance Method Details

#resolveObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/automate-em/core/resolver_pool.rb', line 61

def resolve 
	begin
		ip = Resolv.getaddress(@hostname)
		EM.schedule do
			self.succeed(ip)
		end
	rescue => e
		EM.schedule do
			self.fail(e)
		end
	end
end