Class: SolidObjects::CallerProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/solid_objects/caller_process.rb,
sig/generated/lib/solid_objects/caller_process.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCallerProcess

Returns a new instance of CallerProcess.

RBS:

  • () -> void



10
11
12
13
14
# File 'lib/solid_objects/caller_process.rb', line 10

def initialize
  @mutex = Thread::Mutex.new
  @process_id = nil
  @registry = nil
end

Instance Attribute Details

#mutexObject (readonly)

Returns the value of attribute mutex.

Returns:

  • (Object)


28
29
30
# File 'lib/solid_objects/caller_process.rb', line 28

def mutex
  @mutex
end

#registryObject (readonly)

Returns the value of attribute registry.

Returns:

  • (Object)


28
29
30
# File 'lib/solid_objects/caller_process.rb', line 28

def registry
  @registry
end

Instance Method Details

#process_registryProcessRegistry

RBS:

  • () -> ProcessRegistry

Returns:



17
18
19
20
21
22
23
24
# File 'lib/solid_objects/caller_process.rb', line 17

def process_registry
  mutex.synchronize do
    reset_after_fork
    register unless reusable_registry?
    registry.heartbeat
    registry
  end
end

#registerProcessRegistry

RBS:

  • () -> ProcessRegistry

Returns:



48
49
50
51
52
53
54
55
# File 'lib/solid_objects/caller_process.rb', line 48

def register
  @registry = ProcessRegistry.new
  registry.register(
    kind: "caller",
    metadata: { execution: "synchronous" }
  )
  registry
end

#reset_after_forkvoid

This method returns an undefined value.

RBS:

  • () -> void



31
32
33
34
35
36
# File 'lib/solid_objects/caller_process.rb', line 31

def reset_after_fork
  return if @process_id == ::Process.pid

  @process_id = ::Process.pid
  @registry = nil
end

#reusable_registry?Boolean

RBS:

  • () -> bool

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'lib/solid_objects/caller_process.rb', line 39

def reusable_registry?
  return false unless registry&.process_record

  registry.process_record.reload.shutdown_state == "running"
rescue ActiveRecord::RecordNotFound
  false
end