Class: ActiveSupport::Testing::Parallelization
- Inherits:
-
Object
- Object
- ActiveSupport::Testing::Parallelization
show all
- Defined in:
- lib/active_support/testing/parallelization.rb,
lib/active_support/testing/parallelization/server.rb,
lib/active_support/testing/parallelization/worker.rb
Overview
Defined Under Namespace
Classes: PrerecordResultClass, Server, Worker
Constant Summary
collapse
- @@after_fork_hooks =
[]
- @@run_cleanup_hooks =
[]
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Parallelization.
28
29
30
31
32
33
|
# File 'lib/active_support/testing/parallelization.rb', line 28
def initialize(worker_count)
@worker_count = worker_count
@queue_server = Server.new
@worker_pool = []
@url = DRb.start_service("drbunix:", @queue_server).uri
end
|
Class Method Details
.after_fork_hook(&blk) ⇒ Object
14
15
16
|
# File 'lib/active_support/testing/parallelization.rb', line 14
def self.after_fork_hook(&blk)
@@after_fork_hooks << blk
end
|
.run_cleanup_hook(&blk) ⇒ Object
22
23
24
|
# File 'lib/active_support/testing/parallelization.rb', line 22
def self.run_cleanup_hook(&blk)
@@run_cleanup_hooks << blk
end
|
Instance Method Details
41
42
43
|
# File 'lib/active_support/testing/parallelization.rb', line 41
def <<(work)
@queue_server << work
end
|
49
50
51
52
|
# File 'lib/active_support/testing/parallelization.rb', line 49
def shutdown
@queue_server.shutdown
@worker_pool.each { |pid| Process.waitpid pid }
end
|
45
46
47
|
# File 'lib/active_support/testing/parallelization.rb', line 45
def size
@worker_count
end
|
35
36
37
38
39
|
# File 'lib/active_support/testing/parallelization.rb', line 35
def start
@worker_pool = @worker_count.times.map do |worker|
Worker.new(worker, @url).start
end
end
|