Class: Evilution::Parallel::WorkQueue Private

Inherits:
Object
  • Object
show all
Defined in:
lib/evilution/parallel/work_queue/collection_state.rb,
lib/evilution/parallel/work_queue.rb,
lib/evilution/parallel/work_queue/worker_stat.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

CollectionState is a top-level private constant on WorkQueue (not under a sub-namespace) so Dispatcher accesses it via const_get.

Defined Under Namespace

Modules: Channel, Validators Classes: Dispatcher, Unfinished, Worker, WorkerStat

Constant Summary collapse

SHUTDOWN =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

:__shutdown__
STATS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

:__stats__
TIMING_GRACE_PERIOD =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

5
TIMED_OUT =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Unfinished.new(reason: :timeout)
DIED =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Unfinished.new(reason: :died)

Instance Method Summary collapse

Constructor Details

#initialize(size:, hooks: nil, prefetch: 1, item_timeout: nil, worker_max_items: nil) ⇒ WorkQueue

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of WorkQueue.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/evilution/parallel/work_queue.rb', line 20

def initialize(size:, hooks: nil, prefetch: 1, item_timeout: nil, worker_max_items: nil)
  Validators::PositiveInt.call!(:size, size)
  Validators::PositiveInt.call!(:prefetch, prefetch)
  Validators::OptionalPositiveNumber.call!(:item_timeout, item_timeout)
  Validators::OptionalPositiveInt.call!(:worker_max_items, worker_max_items)

  @size = size
  @hooks = hooks
  @prefetch = prefetch
  @item_timeout = item_timeout
  @worker_max_items = worker_max_items
  @worker_stats = []
end

Instance Method Details

#map(items, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/evilution/parallel/work_queue.rb', line 34

def map(items, &block)
  return [] if items.empty?

  workers = (0...[@size, items.length].min).map { |i| spawn_one(i, &block) }
  dispatcher = build_dispatcher(workers, items, &block)

  retired = []
  begin
    run_result = dispatcher.run
    retired = run_result.retired
    raise dispatcher.first_error if dispatcher.first_error

    run_result.results
  ensure
    cleanup_workers(workers, retired)
  end
end

#worker_statsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



52
53
54
# File 'lib/evilution/parallel/work_queue.rb', line 52

def worker_stats
  @worker_stats.map { |stat| stat.dup.freeze }
end