Class: Blitz::Traceroute

Inherits:
Object
  • Object
show all
Defined in:
lib/blitz/traceroute.rb,
lib/blitz/traceroute/error.rb

Defined Under Namespace

Classes: Error, Result

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Traceroute

:nodoc:



30
31
32
33
# File 'lib/blitz/traceroute.rb', line 30

def initialize json # :nodoc:
    @job_id = json['job_id']
    @region = json['region']
end

Instance Attribute Details

#job_idObject (readonly)

:nodoc:



27
28
29
# File 'lib/blitz/traceroute.rb', line 27

def job_id
  @job_id
end

#regionObject (readonly)

:nodoc:



28
29
30
# File 'lib/blitz/traceroute.rb', line 28

def region
  @region
end

Class Method Details

.execute(args) ⇒ Object



17
18
19
# File 'lib/blitz/traceroute.rb', line 17

def self.execute args
    self.queue(args).result
end

.queue(args) ⇒ Object

:nodoc:

Raises:



21
22
23
24
25
# File 'lib/blitz/traceroute.rb', line 21

def self.queue args # :nodoc:
    res = Command::API.client.traceroute_execute args
    raise Error.new(res) if res['error']
    return self.new res
end

Instance Method Details

#abort!Object

:nodoc:



75
76
77
# File 'lib/blitz/traceroute.rb', line 75

def abort! # :nodoc:
    Command::API.client.abort_job job_id rescue nil
end

#result(&block) ⇒ Object

:nodoc:



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/blitz/traceroute.rb', line 35

def result &block # :nodoc:
    last = nil
    while true
        sleep 2.0

        job = Command::API.client.job_status job_id
        if job['error']
            raise Error
        end
        
        result = job['result']
        next if job['status'] == 'queued'
        next if job['status'] == 'running' and not result

        raise Error if not result

        error = result['error']
        if error
            if error == 'dns'
                raise Error::DNS.new(result)
            elsif error == 'parse'
                raise Error::Parse.new(result)
            else
                raise Error
            end
        end
        
        last = Result.new(job)
        continue = yield last rescue false
        if continue == false
            abort!
            break
        end
        
        break if job['status'] == 'completed'
    end
    
    return last
end