Class: XPool::Process

Inherits:
Object
  • Object
show all
Defined in:
lib/xpool/process.rb

Instance Method Summary collapse

Constructor Details

#initializeXPool::Process

Returns an instance of XPool::Process



6
7
8
# File 'lib/xpool/process.rb', line 6

def initialize
  @id = spawn
end

Instance Method Details

#alive?Boolean

Returns true when the process is still running.

Returns:

  • (Boolean)

    Returns true when the process is still running.



93
94
95
# File 'lib/xpool/process.rb', line 93

def alive?
  !dead?
end

#backtraceArray<String>

If a process has failed (see #failed?) this method returns the backtrace of the exception that caused the process to fail.

Returns:

  • (Array<String>)

    Returns the backtrace.



113
114
115
116
# File 'lib/xpool/process.rb', line 113

def backtrace
  synchronize!
  @states[:backtrace]
end

#busy?Boolean

Returns true when the process is executing a unit of work.

Returns:

  • (Boolean)

    Returns true when the process is executing a unit of work.



67
68
69
70
# File 'lib/xpool/process.rb', line 67

def busy?
  synchronize!
  @states[:busy]
end

#dead?Boolean

Returns true when the process has shutdown.

Returns:

  • (Boolean)

    Returns true when the process has shutdown.



101
102
103
104
# File 'lib/xpool/process.rb', line 101

def dead?
  synchronize!
  @states[:dead]
end

#failed?Boolean

Returns true when the process has failed due to an unhandled exception.

Returns:

  • (Boolean)

    Returns true when the process has failed due to an unhandled exception.



84
85
86
87
# File 'lib/xpool/process.rb', line 84

def failed?
  synchronize!
  @states[:failed]
end

#frequencyFixnum

Returns The number of times the process has been asked to schedule work.

Returns:

  • (Fixnum)

    The number of times the process has been asked to schedule work.



36
37
38
# File 'lib/xpool/process.rb', line 36

def frequency
  @frequency
end

#idle?Boolean

Returns true when the process is not executing a unit of work.

Returns:

  • (Boolean)

    Returns true when the process is not executing a unit of work.



76
77
78
# File 'lib/xpool/process.rb', line 76

def idle?
  !busy?
end

#restartFixnum

Returns the process ID of the new process.

Returns:

  • (Fixnum)

    Returns the process ID of the new process.



122
123
124
125
# File 'lib/xpool/process.rb', line 122

def restart
  shutdown
  @id = spawn
end

#schedule(unit, *args) ⇒ XPool::Process

Returns self

Parameters:

  • unit (#run)

    The unit of work

  • *args (Object)

    A variable number of arguments to be passed to #run

Returns:

Raises:

  • (RuntimeError)

    When the process is dead.



53
54
55
56
57
58
59
60
61
# File 'lib/xpool/process.rb', line 53

def schedule(unit,*args)
  if dead?
    raise RuntimeError,
      "cannot schedule work on a dead process (with ID: #{@id})"
  end
  @frequency += 1
  @channel.put unit: unit, args: args
  self
end

#shutdownvoid

This method returns an undefined value.

A graceful shutdown of the process.

The signal ‘SIGUSR1’ is caught in the subprocess and exit is performed through Kernel#exit after the process has finished executing its work.



19
20
21
# File 'lib/xpool/process.rb', line 19

def shutdown
  _shutdown 'SIGUSR1' unless @shutdown
end

#shutdown!void

This method returns an undefined value.

A non-graceful shutdown through SIGKILL.



28
29
30
# File 'lib/xpool/process.rb', line 28

def shutdown!
  _shutdown 'SIGKILL' unless @shutdown
end