Skip to content

Commit 9a40186

Browse files
committed
Renamed WorkerTasks to WorkerPool.
1 parent 7bc937e commit 9a40186

File tree

3 files changed

+40
-40
lines changed

3 files changed

+40
-40
lines changed

lib/ronin/recon/engine.rb

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# along with ronin-recon. If not, see <https://www.gnu.org/licenses/>.
1919
#
2020

21-
require 'ronin/recon/worker_tasks'
21+
require 'ronin/recon/worker_pool'
2222
require 'ronin/recon/value_status'
2323
require 'ronin/recon/graph'
2424
require 'ronin/recon/scope'
@@ -88,8 +88,8 @@ def initialize(values, workers: WorkerSet.default,
8888
@scope = Scope.new(values, ignore: ignore)
8989

9090
@worker_classes = {}
91-
@worker_tasks = {}
92-
@worker_task_count = 0
91+
@worker_pools = {}
92+
@worker_pool_count = 0
9393

9494
@value_status = ValueStatus.new
9595
@graph = Graph.new
@@ -186,9 +186,9 @@ def run(task=Async::Task.current)
186186
end
187187

188188
# start all work groups
189-
@worker_tasks.each_value do |worker_tasks|
190-
worker_tasks.each do |worker_task|
191-
worker_task.start(task)
189+
@worker_pools.each_value do |worker_pools|
190+
worker_pools.each do |worker_pool|
191+
worker_pool.start(task)
192192
end
193193
end
194194
end
@@ -207,13 +207,13 @@ def run(task=Async::Task.current)
207207
def add_worker(worker_class, concurrency: worker_class.concurrency,
208208
params: nil)
209209
worker = worker_class.new(params: params)
210-
worker_tasks = WorkerTasks.new(worker, concurrency: concurrency,
211-
output_queue: @output_queue,
212-
logger: @logger)
210+
worker_pools = WorkerPool.new(worker, concurrency: concurrency,
211+
output_queue: @output_queue,
212+
logger: @logger)
213213

214214
worker_class.accepts.each do |value_class|
215215
(@worker_classes[value_class] ||= []) << worker_class
216-
(@worker_tasks[value_class] ||= []) << worker_tasks
216+
(@worker_pools[value_class] ||= []) << worker_pools
217217
end
218218
end
219219

@@ -405,7 +405,7 @@ def process(mesg)
405405
#
406406
def process_worker_started(mesg)
407407
@logger.debug("Worker started: #{mesg.worker}")
408-
@worker_task_count += 1
408+
@worker_pool_count += 1
409409
end
410410

411411
#
@@ -418,7 +418,7 @@ def process_worker_started(mesg)
418418
#
419419
def process_worker_stopped(mesg)
420420
@logger.debug("Worker shutdown: #{mesg.worker}")
421-
@worker_task_count -= 1
421+
@worker_pool_count -= 1
422422
end
423423

424424
#
@@ -537,18 +537,18 @@ def enqueue_mesg(mesg)
537537
@value_status.value_enqueued(worker_class,value)
538538
end
539539

540-
@worker_tasks[value.class].each do |worker_task|
541-
worker_task.enqueue_mesg(mesg)
540+
@worker_pools[value.class].each do |worker_pool|
541+
worker_pool.enqueue_mesg(mesg)
542542
end
543543
end
544544
when Message::SHUTDOWN
545545
@logger.debug("Shutting down ...")
546546

547-
@worker_tasks.each_value do |worker_tasks|
548-
worker_tasks.each do |worker_task|
549-
@logger.debug("Shutting down worker: #{worker_task.worker} ...")
547+
@worker_pools.each_value do |worker_pools|
548+
worker_pools.each do |worker_pool|
549+
@logger.debug("Shutting down worker: #{worker_pool.worker} ...")
550550

551-
worker_task.enqueue_mesg(mesg)
551+
worker_pool.enqueue_mesg(mesg)
552552
end
553553
end
554554
else
@@ -570,15 +570,15 @@ def enqueue_value(value)
570570
end
571571

572572
#
573-
# Sends the shutdown message and waits for all worker tasks to shutdown.
573+
# Sends the shutdown message and waits for all worker pools to shutdown.
574574
#
575575
# @api private
576576
#
577577
def shutdown!
578578
enqueue_mesg(Message::SHUTDOWN)
579579

580580
# wait until all workers report that they have exited
581-
until @worker_task_count == 0
581+
until @worker_pool_count == 0
582582
process(@output_queue.dequeue)
583583
end
584584
end

lib/ronin/recon/worker_tasks.rb renamed to lib/ronin/recon/worker_pool.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
module Ronin
3333
module Recon
3434
#
35-
# Contains the `Async::Task` objects that process messages from the input
36-
# queue and sends messages to the output queue.
35+
# Contains the `Async::Task` objects for a worker, that process messages
36+
# from the input queue and sends messages to the output queue.
3737
#
3838
# @api private
3939
#
40-
class WorkerTasks
40+
class WorkerPool
4141

4242
# The recon worker's ID.
4343
#
@@ -70,7 +70,7 @@ class WorkerTasks
7070
attr_reader :logger
7171

7272
#
73-
# Initializes the worker tasks.
73+
# Initializes the worker pool.
7474
#
7575
# @param [Worker] worker
7676
# The initialized worker object.
@@ -154,7 +154,7 @@ def run
154154
end
155155

156156
#
157-
# Starts the worker.
157+
# Starts the worker pool.
158158
#
159159
# @param [Async::Task] task
160160
# The optional async task to register the worker under.
@@ -171,18 +171,18 @@ def start(task=Async::Task.current)
171171
end
172172

173173
#
174-
# Marks the worker as running.
174+
# Marks the worker pool as running.
175175
#
176176
def started!
177-
# send a message to the engine that the worker task has started
177+
# send a message to the engine that the worker pool has started
178178
enqueue(Message::WorkerStarted.new(@worker))
179179
end
180180

181181
#
182-
# Marks the worker as stopped.
182+
# Marks the worker pool as stopped.
183183
#
184184
def stopped!
185-
# send a message to the engine that the worker task has stopped
185+
# send a message to the engine that the worker pool has stopped
186186
enqueue(Message::WorkerStopped.new(@worker))
187187
end
188188

spec/worker_tasks_spec.rb renamed to spec/worker_pool_spec.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
require 'spec_helper'
2-
require 'ronin/recon/worker_tasks'
2+
require 'ronin/recon/worker_pool'
33
require 'ronin/recon/worker'
44
require 'ronin/recon/message/value'
55

6-
describe Ronin::Recon::WorkerTasks do
6+
describe Ronin::Recon::WorkerPool do
77
subject { described_class.new(worker, output_queue: Async::Queue.new) }
88

9-
module TestWorkerTasks
9+
module TestWorkerPool
1010
class TestWorker < Ronin::Recon::Worker
1111
def process(value)
1212
yield Ronin::Recon::Values::Domain.new('example.com')
@@ -20,7 +20,7 @@ def process(value); end
2020
end
2121

2222
describe "#initialize" do
23-
let(:worker) { TestWorkerTasks::TestWorker.new }
23+
let(:worker) { TestWorkerPool::TestWorker.new }
2424

2525
it "must initialize #worker worker object" do
2626
expect(subject.worker).to be(worker)
@@ -46,7 +46,7 @@ def process(value); end
4646
describe "#enqueue_mesg" do
4747
context "for Message::SHUTDOWN" do
4848
let(:mesg_value) { Ronin::Recon::Message::SHUTDOWN }
49-
let(:worker) { TestWorkerTasks::TestWorkerWithConcurrency.new }
49+
let(:worker) { TestWorkerPool::TestWorkerWithConcurrency.new }
5050

5151
it "must enqueue Message::Shutdown into #input_queue 2 times" do
5252
Async { subject.enqueue_mesg(mesg_value) }
@@ -58,7 +58,7 @@ def process(value); end
5858

5959
context "for other Message's" do
6060
let(:mesg_value) { Ronin::Recon::Message::Value }
61-
let(:worker) { TestWorkerTasks::TestWorker.new }
61+
let(:worker) { TestWorkerPool::TestWorker.new }
6262

6363
it "must enqueue Message into #input_queue" do
6464
Async { subject.enqueue_mesg(mesg_value) }
@@ -69,7 +69,7 @@ def process(value); end
6969
end
7070

7171
describe "#run" do
72-
let(:worker) { TestWorkerTasks::TestWorker.new }
72+
let(:worker) { TestWorkerPool::TestWorker.new }
7373
let(:shutdown_mesg) { Ronin::Recon::Message::SHUTDOWN }
7474
let(:value_mesg) { Ronin::Recon::Message::Value.new("value") }
7575

@@ -102,7 +102,7 @@ def process(value); end
102102
end
103103

104104
describe "#start" do
105-
let(:worker) { TestWorkerTasks::TestWorkerWithConcurrency.new }
105+
let(:worker) { TestWorkerPool::TestWorkerWithConcurrency.new }
106106
let(:shutdown_mesg) { Ronin::Recon::Message::SHUTDOWN }
107107
let(:value_mesg) { Ronin::Recon::Message::Value.new("value") }
108108

@@ -117,7 +117,7 @@ def process(value); end
117117
end
118118

119119
describe "#started!" do
120-
let(:worker) { TestWorkerTasks::TestWorker.new }
120+
let(:worker) { TestWorkerPool::TestWorker.new }
121121

122122
it "must enqueue Message::WorkerStarted instance into #output_queue" do
123123
Async { subject.started! }
@@ -128,7 +128,7 @@ def process(value); end
128128
end
129129

130130
describe "#stopped!" do
131-
let(:worker) { TestWorkerTasks::TestWorker.new }
131+
let(:worker) { TestWorkerPool::TestWorker.new }
132132

133133
it "must enqueue Message::WorkerStopped instance into #output_queue" do
134134
Async { subject.stopped! }
@@ -139,7 +139,7 @@ def process(value); end
139139
end
140140

141141
describe "#enqueue" do
142-
let(:worker) { TestWorkerTasks::TestWorker.new }
142+
let(:worker) { TestWorkerPool::TestWorker.new }
143143
let(:mesg) { Ronin::Recon::Message::JobFailed }
144144

145145
it "must enqueue Message into #output_queue" do

0 commit comments

Comments
 (0)