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.
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.
Constructor Details
#initialize(options = {}) ⇒ Job
Returns a new instance of Job.
48 49 50 51 52 53 |
# File 'lib/arachni/browser_cluster/job.rb', line 48 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 |
Instance Method Details
#==(other) ⇒ Object
159 160 161 |
# File 'lib/arachni/browser_cluster/job.rb', line 159 def ==( other ) hash == other.hash end |
#clean_copy ⇒ Job
Returns Copy of ‘self` with any resources set by #configure_and_run removed.
117 118 119 |
# File 'lib/arachni/browser_cluster/job.rb', line 117 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.
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 |
#dup ⇒ Job
Returns Copy of ‘self`.
123 124 125 |
# File 'lib/arachni/browser_cluster/job.rb', line 123 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`.
133 134 135 |
# File 'lib/arachni/browser_cluster/job.rb', line 133 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`.
145 146 147 |
# File 'lib/arachni/browser_cluster/job.rb', line 145 def forward_as( job_type, = {} ) job_type.new ( ) end |
#hash ⇒ Object
155 156 157 |
# File 'lib/arachni/browser_cluster/job.rb', line 155 def hash @options.hash end |
#id ⇒ Integer
Returns ID, used by the Arachni::BrowserCluster, to tie requests to callbacks.
151 152 153 |
# File 'lib/arachni/browser_cluster/job.rb', line 151 def id @id end |
#never_ending=(bool) ⇒ Bool
Returns ‘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.
69 70 71 |
# File 'lib/arachni/browser_cluster/job.rb', line 69 def never_ending? !!@never_ending end |
#run ⇒ Object
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.
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/arachni/browser_cluster/job.rb', line 103 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 |