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



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

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

Instance Attribute Details

#mutexObject (readonly)

Returns the value of attribute mutex.

Returns:

  • (Object)


41
42
43
# File 'lib/solid_objects/caller_process.rb', line 41

def mutex
  @mutex
end

#registryObject (readonly)

Returns the value of attribute registry.

Returns:

  • (Object)


41
42
43
# File 'lib/solid_objects/caller_process.rb', line 41

def registry
  @registry
end

Instance Method Details

#install_shutdown_hookvoid

This method returns an undefined value.

RBS:

  • () -> void



73
74
75
76
77
78
# File 'lib/solid_objects/caller_process.rb', line 73

def install_shutdown_hook
  return if @shutdown_hook_installed

  @shutdown_hook_installed = true
  at_exit { stop_after_exit }
end

#process_registryProcessRegistry

RBS:

  • () -> ProcessRegistry

Returns:



19
20
21
22
23
24
25
26
27
# File 'lib/solid_objects/caller_process.rb', line 19

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

#registerProcessRegistry

RBS:

  • () -> ProcessRegistry

Returns:



63
64
65
66
67
68
69
70
# File 'lib/solid_objects/caller_process.rb', line 63

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

#reset_after_forkvoid

This method returns an undefined value.

RBS:

  • () -> void



44
45
46
47
48
49
# File 'lib/solid_objects/caller_process.rb', line 44

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

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

#reusable_registry?Boolean

RBS:

  • () -> bool

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
60
# File 'lib/solid_objects/caller_process.rb', line 52

def reusable_registry?
  return false unless registry&.process_record

  SolidObjects.database_adapter.with_lock_retry do
    registry.process_record.reload.shutdown_state == "running"
  end
rescue ActiveRecord::RecordNotFound
  false
end

#stopBoolean

RBS:

  • () -> bool

Returns:

  • (Boolean)


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

def stop
  mutex.synchronize do
    return false unless @process_id == ::Process.pid
    return false unless registry&.process_record

    registry.stop.tap { @registry = nil }
  end
end

#stop_after_exitBoolean

RBS:

  • () -> bool

Returns:

  • (Boolean)


81
82
83
84
85
# File 'lib/solid_objects/caller_process.rb', line 81

def stop_after_exit
  stop
rescue
  false
end