Class: Mutant::Parallel::Worker Private

Inherits:
Object
  • Object
show all
Includes:
Unparser::Adamantium
Defined in:
lib/mutant/parallel/worker.rb

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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.start(world:, block:, process_name:, **attributes) ⇒ 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.

rubocop:disable Metrics/MethodLength rubocop:disable Metrics/ParameterLists



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mutant/parallel/worker.rb', line 24

def self.start(world:, block:, process_name:, **attributes)
  io      = world.io
  process = world.process

  request  = Pipe.from_io(io)
  response = Pipe.from_io(io)

  pid = process.fork do
    world.thread.current.name = process_name
    world.process.setproctitle(process_name)

    Child.new(
      block:      block,
      connection: Pipe::Connection.from_pipes(
        marshal: world.marshal,
        reader:  request,
        writer:  response
      )
    ).call
  end

  new(
    pid:        pid,
    process:    process,
    connection: Pipe::Connection.from_pipes(
      marshal: world.marshal,
      reader:  response,
      writer:  request
    ),
    **attributes
  )
end

Instance Method Details

#callself

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.

Run worker payload

Returns:

  • (self)


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/mutant/parallel/worker.rb', line 62

def call
  loop do
    job = next_job or break

    job_start(job)

    result = connection.call(job.payload)

    job_done(job)

    break if add_result(result)
  end

  finalize

  self
end

#joinObject

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.



80
81
82
83
84
# File 'lib/mutant/parallel/worker.rb', line 80

def join
  process.kill('TERM', pid)
  process.wait(pid)
  self
end