Class: Arachni::BrowserCluster::Job Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/arachni/browser_cluster/job.rb,
lib/arachni/browser_cluster/job/result.rb

Overview

This class is abstract.

Represents a job to be passed to the #queue for deferred execution.

Author:

Defined Under Namespace

Classes: Error, Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Job

Returns a new instance of Job.

Parameters:

  • options (Hash) (defaults to: {})


52
53
54
55
56
57
# File 'lib/arachni/browser_cluster/job.rb', line 52

def initialize( options = {} )
    @options      = options.dup
    @options[:id] = @id = options.delete(:id) || increment_id

    options.each { |k, v| options[k] = send( "#{k}=", v ) }
end

Instance Attribute Details

#browserWorker (readonly)

Returns Browser to use in order to perform the relevant task – set by Worker#run_job via #configure_and_run.

Returns:



38
39
40
# File 'lib/arachni/browser_cluster/job.rb', line 38

def browser
  @browser
end

#forwarderJob

Returns Forwarder [Job] in case ‘self` is a result of a forward operation.

Returns:

  • (Job)

    Forwarder [Job] in case ‘self` is a result of a forward operation.

See Also:



45
46
47
# File 'lib/arachni/browser_cluster/job.rb', line 45

def forwarder
  @forwarder
end

#timeInteger

Returns Duration of the job, in seconds.

Returns:

  • (Integer)

    Duration of the job, in seconds.



49
50
51
# File 'lib/arachni/browser_cluster/job.rb', line 49

def time
  @time
end

Instance Method Details

#==(other) ⇒ Object



179
180
181
# File 'lib/arachni/browser_cluster/job.rb', line 179

def ==( other )
    hash == other.hash
end

#clean_copyJob

Returns Copy of ‘self` with any resources set by #configure_and_run removed.

Returns:



134
135
136
# File 'lib/arachni/browser_cluster/job.rb', line 134

def clean_copy
    dup.tap { |j| j.remove_resources }
end

#configure_and_run(browser) ⇒ Object

Configures the job with the given resources, runs the payload and then removes the assigned resources.

Parameters:



103
104
105
106
107
108
# File 'lib/arachni/browser_cluster/job.rb', line 103

def configure_and_run( browser )
    set_resources( browser )
    run
ensure
    remove_resources
end

#dupJob

Returns Copy of ‘self`.

Returns:

  • (Job)

    Copy of ‘self`



140
141
142
143
144
145
# File 'lib/arachni/browser_cluster/job.rb', line 140

def dup
    n = self.class.new( add_id( @options ) )
    n.time = time
    n.timed_out!( time ) if timed_out?
    n
end

#forward(options = {}) ⇒ Job

Returns Re-used request (mainly its #id and thus its callback as well), configured with the given ‘options`.

Parameters:

Returns:

  • (Job)

    Re-used request (mainly its #id and thus its callback as well), configured with the given ‘options`.



153
154
155
# File 'lib/arachni/browser_cluster/job.rb', line 153

def forward( options = {} )
    self.class.new forward_options( options )
end

#forward_as(job_type, options = {}) ⇒ Job

Returns Forwarded request (preserving its #id and thus its callback as well), configured with the given ‘options`.

Parameters:

Returns:

  • (Job)

    Forwarded request (preserving its #id and thus its callback as well), configured with the given ‘options`.



165
166
167
# File 'lib/arachni/browser_cluster/job.rb', line 165

def forward_as( job_type, options = {} )
    job_type.new forward_options( options )
end

#hashObject



175
176
177
# File 'lib/arachni/browser_cluster/job.rb', line 175

def hash
    @options.hash
end

#idInteger

Returns ID, used by the Arachni::BrowserCluster, to tie requests to callbacks.

Returns:



171
172
173
# File 'lib/arachni/browser_cluster/job.rb', line 171

def id
    @id
end

#never_ending=(bool) ⇒ Bool

Returns ‘true` if this job never ends, `false` otherwise.

Returns:

  • (Bool)

    ‘true` if this job never ends, `false` otherwise.



92
93
94
95
# File 'lib/arachni/browser_cluster/job.rb', line 92

def never_ending=( bool )
    @options[:never_ending] = bool
    @never_ending = bool
end

#never_ending?Bool

Returns ‘true` if this job never ends, `false` otherwise.

Returns:

  • (Bool)

    ‘true` if this job never ends, `false` otherwise.

See Also:

  • #never_ending


86
87
88
# File 'lib/arachni/browser_cluster/job.rb', line 86

def never_ending?
    !!@never_ending
end

#runObject

This method is abstract.
Note:

The following resources will be available at the time of execution:

Encapsulates the job payload.



79
80
# File 'lib/arachni/browser_cluster/job.rb', line 79

def run
end

#save_result(data) ⇒ Object

Forwards the resulting ‘data` to the browser cluster which then forwards it to the entity that queued the job.

The result type will be the closest Result class to the Arachni::BrowserCluster::Job type. If the job is of type ‘MyJob`, `MyJob::Result` will be used, the default if Result.

Parameters:



120
121
122
123
124
125
126
127
128
129
# File 'lib/arachni/browser_cluster/job.rb', line 120

def save_result( data )
    # Results coming in after the job has already finished won't have a
    # browser.
    return if !browser

    browser.master.handle_job_result(
        self.class::Result.new( data.merge( job: self.clean_copy ) )
    )
    nil
end

#timed_out!(time) ⇒ Object

Parameters:

  • time (Integer)

    Amount of #time elapsed until time-out.



61
62
63
64
# File 'lib/arachni/browser_cluster/job.rb', line 61

def timed_out!( time )
    @timed_out = true
    @time = time
end

#timed_out?Bool

Returns ‘true` if timed-ot, `false` otherwise.

Returns:

  • (Bool)

    ‘true` if timed-ot, `false` otherwise.



68
69
70
# File 'lib/arachni/browser_cluster/job.rb', line 68

def timed_out?
    !!@timed_out
end