Class: ActiveSupport::Testing::Parallelization
- Inherits:
-
Object
- Object
- ActiveSupport::Testing::Parallelization
show all
- Defined in:
- activesupport/lib/active_support/testing/parallelization.rb,
activesupport/lib/active_support/testing/parallelization/server.rb,
activesupport/lib/active_support/testing/parallelization/worker.rb
Overview
Defined Under Namespace
Classes: PrerecordResultClass, Server, Worker
Constant Summary
collapse
- @@before_fork_hooks =
[]
- @@after_fork_hooks =
[]
- @@run_cleanup_hooks =
[]
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Parallelization.
36
37
38
39
40
41
|
# File 'activesupport/lib/active_support/testing/parallelization.rb', line 36
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
22
23
24
|
# File 'activesupport/lib/active_support/testing/parallelization.rb', line 22
def self.after_fork_hook(&blk)
@@after_fork_hooks << blk
end
|
.before_fork_hook(&blk) ⇒ Object
14
15
16
|
# File 'activesupport/lib/active_support/testing/parallelization.rb', line 14
def self.before_fork_hook(&blk)
@@before_fork_hooks << blk
end
|
.run_cleanup_hook(&blk) ⇒ Object
30
31
32
|
# File 'activesupport/lib/active_support/testing/parallelization.rb', line 30
def self.run_cleanup_hook(&blk)
@@run_cleanup_hooks << blk
end
|
Instance Method Details
54
55
56
|
# File 'activesupport/lib/active_support/testing/parallelization.rb', line 54
def <<(work)
@queue_server << work
end
|
#before_fork ⇒ Object
43
44
45
|
# File 'activesupport/lib/active_support/testing/parallelization.rb', line 43
def before_fork
Parallelization.before_fork_hooks.each(&:call)
end
|
62
63
64
65
|
# File 'activesupport/lib/active_support/testing/parallelization.rb', line 62
def shutdown
@queue_server.shutdown
@worker_pool.each { |pid| Process.waitpid pid }
end
|
58
59
60
|
# File 'activesupport/lib/active_support/testing/parallelization.rb', line 58
def size
@worker_count
end
|
47
48
49
50
51
52
|
# File 'activesupport/lib/active_support/testing/parallelization.rb', line 47
def start
before_fork
@worker_pool = @worker_count.times.map do |worker|
Worker.new(worker, @url).start
end
end
|