Class: Blitz::Curl::Sprint

Inherits:
Object
  • Object
show all
Defined in:
lib/blitz/curl/sprint.rb

Overview

Use this to run a sprint against your app. The return values include the response time, the region from which the sprint was run along with the full request and response headers and the response body.

Defined Under Namespace

Classes: Request, Response, Result, Step

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Sprint

:nodoc:



127
128
129
# File 'lib/blitz/curl/sprint.rb', line 127

def initialize args # :nodoc:
    @args = args
end

Instance Attribute Details

#argsObject (readonly)

:nodoc:



125
126
127
# File 'lib/blitz/curl/sprint.rb', line 125

def args
  @args
end

#job_idObject (readonly)

:nodoc:



123
124
125
# File 'lib/blitz/curl/sprint.rb', line 123

def job_id
  @job_id
end

#regionObject (readonly)

:nodoc:



124
125
126
# File 'lib/blitz/curl/sprint.rb', line 124

def region
  @region
end

Instance Method Details

#abortObject

:nodoc:



167
168
169
# File 'lib/blitz/curl/sprint.rb', line 167

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

#executeObject

The primary method to execute a sprint from region. This method supports all of the arguments that the blitz bar supports. For example:

result = Blitz::Curl.parse('-r california www.example.com').execute


108
109
110
111
# File 'lib/blitz/curl/sprint.rb', line 108

def execute
    queue
    result
end

#queueObject

:nodoc:

Raises:



113
114
115
116
117
118
119
120
121
# File 'lib/blitz/curl/sprint.rb', line 113

def queue # :nodoc:
    args.delete 'pattern'
    args.delete :pattern

    res = Command::API.client.curl_execute args
    raise Error.new(res) if res['error']
    @job_id = res['job_id']
    @region = res['region']
end

#resultObject

:nodoc:



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/blitz/curl/sprint.rb', line 131

def result # :nodoc:
    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 == 'connect'
                raise Error::Connect.new(result)
            elsif error == 'timeout'
                raise Error::Timeout.new(result)
            elsif error == 'parse'
                raise Error::Parse.new(result)
            elsif error == 'assert'
                raise Error::Status.new(result)
            else
                raise Error
            end
        end
        
        return Result.new(job)
    end
end