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: {})


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

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

Instance Method Details

#==(other) ⇒ Object



155
156
157
# File 'lib/arachni/browser_cluster/job.rb', line 155

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

#clean_copyJob

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

Returns:



113
114
115
# File 'lib/arachni/browser_cluster/job.rb', line 113

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:



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

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

#dupJob

Returns Copy of ‘self`.

Returns:

  • (Job)

    Copy of ‘self`



119
120
121
# File 'lib/arachni/browser_cluster/job.rb', line 119

def dup
    self.class.new add_id( @options )
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`.



129
130
131
# File 'lib/arachni/browser_cluster/job.rb', line 129

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`.



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

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

#hashObject



151
152
153
# File 'lib/arachni/browser_cluster/job.rb', line 151

def hash
    @options.hash
end

#idInteger

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

Returns:



147
148
149
# File 'lib/arachni/browser_cluster/job.rb', line 147

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.



75
76
77
78
# File 'lib/arachni/browser_cluster/job.rb', line 75

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


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

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.



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

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:



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

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