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::ResourceExploration
Defined Under Namespace
Instance Attribute Summary collapse
-
#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
Forwards the resulting ‘data` to the browser cluster which then forwards it to the entity that queued the job.
- #timed_out!(time) ⇒ Object
-
#timed_out? ⇒ Bool
‘true` if timed-ot, `false` otherwise.
Constructor Details
#initialize(options = {}) ⇒ Job
Returns a new instance of Job.
52 53 54 55 56 57 |
# File 'lib/arachni/browser_cluster/job.rb', line 52 def initialize( = {} ) @options = .dup @options[:id] = @id = .delete(:id) || increment_id .each { |k, v| [k] = send( "#{k}=", v ) } end |
Instance Attribute Details
#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
179 180 181 |
# File 'lib/arachni/browser_cluster/job.rb', line 179 def ==( other ) hash == other.hash end |
#clean_copy ⇒ Job
Returns Copy of ‘self` with any resources set by #configure_and_run removed.
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.
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 |
#dup ⇒ Job
Returns 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`.
153 154 155 |
# File 'lib/arachni/browser_cluster/job.rb', line 153 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`.
165 166 167 |
# File 'lib/arachni/browser_cluster/job.rb', line 165 def forward_as( job_type, = {} ) job_type.new ( ) end |
#hash ⇒ Object
175 176 177 |
# File 'lib/arachni/browser_cluster/job.rb', line 175 def hash @options.hash end |
#id ⇒ Integer
Returns ID, used by the Arachni::BrowserCluster, to tie requests to callbacks.
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.
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.
86 87 88 |
# File 'lib/arachni/browser_cluster/job.rb', line 86 def never_ending? !!@never_ending end |
#run ⇒ Object
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.
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
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.
68 69 70 |
# File 'lib/arachni/browser_cluster/job.rb', line 68 def timed_out? !!@timed_out end |