Class: Arachni::BrowserCluster::Job Abstract
- Defined in:
- lib/arachni/browser_cluster/job.rb,
lib/arachni/browser_cluster/job/result.rb
Overview
Represents a job to be passed to the #queue for deferred execution.
Direct Known Subclasses
Arachni::BrowserCluster::Jobs::BrowserProvider, Arachni::BrowserCluster::Jobs::DOMExploration
Defined Under Namespace
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#browser ⇒ Worker
readonly
Browser to use in order to perform the relevant task -- set by Worker#run_job via #configure_and_run.
-
#forwarder ⇒ Job
Forwarder [Job] in case
self
is a result of a forward operation. -
#time ⇒ Integer
Duration of the job, in seconds.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#clean_copy ⇒ Job
Copy of
self
with any resources set by #configure_and_run removed. -
#configure_and_run(browser) ⇒ Object
Configures the job with the given resources, runs the payload and then removes the assigned resources.
-
#dup ⇒ Job
Copy of
self
. -
#forward(options = {}) ⇒ Job
Re-used request (mainly its #id and thus its callback as well), configured with the given
options
. -
#forward_as(job_type, options = {}) ⇒ Job
Forwarded request (preserving its #id and thus its callback as well), configured with the given
options
. - #hash ⇒ Object
-
#id ⇒ Integer
ID, used by the Arachni::BrowserCluster, to tie requests to callbacks.
-
#initialize(options = {}) ⇒ Job
constructor
A new instance of Job.
-
#never_ending=(bool) ⇒ Bool
true
if this job never ends,false
otherwise. -
#never_ending? ⇒ Bool
true
if this job never ends,false
otherwise. -
#run ⇒ Object
abstract
Encapsulates the job payload.
- #save_result(data) ⇒ Object
- #timed_out!(time) ⇒ Object
-
#timed_out? ⇒ Bool
true
if timed-ot,false
otherwise.
Constructor Details
#initialize(options = {}) ⇒ Job
Returns a new instance of Job.
54 55 56 57 58 59 60 61 |
# File 'lib/arachni/browser_cluster/job.rb', line 54 def initialize( = {} ) @options = .dup @options[:id] = @id = .delete(:id) || increment_id @args = @options[:args] || [] .each { |k, v| [k] = send( "#{k}=", v ) } end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
51 52 53 |
# File 'lib/arachni/browser_cluster/job.rb', line 51 def args @args end |
#browser ⇒ Worker (readonly)
Returns Browser to use in order to perform the relevant task -- set by Worker#run_job via #configure_and_run.
38 39 40 |
# File 'lib/arachni/browser_cluster/job.rb', line 38 def browser @browser end |
#forwarder ⇒ Job
Returns Forwarder [Job] in case self
is a result of a forward operation.
45 46 47 |
# File 'lib/arachni/browser_cluster/job.rb', line 45 def forwarder @forwarder end |
#time ⇒ Integer
Returns 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
185 186 187 |
# File 'lib/arachni/browser_cluster/job.rb', line 185 def ==( other ) hash == other.hash end |
#clean_copy ⇒ Job
Returns Copy of self
with any resources set by #configure_and_run
removed.
138 139 140 |
# File 'lib/arachni/browser_cluster/job.rb', line 138 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.
107 108 109 110 111 112 |
# File 'lib/arachni/browser_cluster/job.rb', line 107 def configure_and_run( browser ) set_resources( browser ) run ensure remove_resources end |
#dup ⇒ Job
Returns Copy of self
.
144 145 146 147 148 149 |
# File 'lib/arachni/browser_cluster/job.rb', line 144 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
.
157 158 159 |
# File 'lib/arachni/browser_cluster/job.rb', line 157 def forward( = {} ) self.class.new ( ) end |
#forward_as(job_type, options = {}) ⇒ Job
Returns Forwarded request (preserving its #id and thus its callback as well),
configured with the given options
.
169 170 171 172 173 |
# File 'lib/arachni/browser_cluster/job.rb', line 169 def forward_as( job_type, = {} ) # Remove the ID because this will be a different class/job type and # we thus need to keep track of it separately in the BrowserCluster. job_type.new ( ).tap { |h| h.delete :id } end |
#hash ⇒ Object
181 182 183 |
# File 'lib/arachni/browser_cluster/job.rb', line 181 def hash @options.hash end |
#id ⇒ Integer
Returns ID, used by the Arachni::BrowserCluster, to tie requests to callbacks.
177 178 179 |
# File 'lib/arachni/browser_cluster/job.rb', line 177 def id @id end |
#never_ending=(bool) ⇒ Bool
Returns true
if this job never ends, false
otherwise.
96 97 98 99 |
# File 'lib/arachni/browser_cluster/job.rb', line 96 def never_ending=( bool ) @options[:never_ending] = bool @never_ending = bool end |
#never_ending? ⇒ Bool
Returns true
if this job never ends, false
otherwise.
90 91 92 |
# File 'lib/arachni/browser_cluster/job.rb', line 90 def never_ending? !!@never_ending end |
#run ⇒ Object
The following resources will be available at the time of execution:
Encapsulates the job payload.
83 84 |
# File 'lib/arachni/browser_cluster/job.rb', line 83 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.
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/arachni/browser_cluster/job.rb', line 124 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
65 66 67 68 |
# File 'lib/arachni/browser_cluster/job.rb', line 65 def timed_out!( time ) @timed_out = true @time = time end |
#timed_out? ⇒ Bool
Returns true
if timed-ot, false
otherwise.
72 73 74 |
# File 'lib/arachni/browser_cluster/job.rb', line 72 def timed_out? !!@timed_out end |