Class: SolidObjects::CallerProcess
- Inherits:
-
Object
- Object
- SolidObjects::CallerProcess
- Defined in:
- lib/solid_objects/caller_process.rb,
sig/generated/lib/solid_objects/caller_process.rbs
Instance Attribute Summary collapse
-
#mutex ⇒ Object
readonly
Returns the value of attribute mutex.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
-
#initialize ⇒ CallerProcess
constructor
A new instance of CallerProcess.
- #install_shutdown_hook ⇒ void
- #process_registry ⇒ ProcessRegistry
- #register ⇒ ProcessRegistry
- #reset_after_fork ⇒ void
- #reusable_registry? ⇒ Boolean
- #stop ⇒ Boolean
- #stop_after_exit ⇒ Boolean
Constructor Details
#initialize ⇒ CallerProcess
Returns a new instance of CallerProcess.
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
#mutex ⇒ Object (readonly)
Returns the value of attribute mutex.
41 42 43 |
# File 'lib/solid_objects/caller_process.rb', line 41 def mutex @mutex end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
41 42 43 |
# File 'lib/solid_objects/caller_process.rb', line 41 def registry @registry end |
Instance Method Details
#install_shutdown_hook ⇒ void
This method returns an undefined value.
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_registry ⇒ ProcessRegistry
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 |
#register ⇒ ProcessRegistry
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_fork ⇒ void
This method returns an undefined value.
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
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 |
#stop ⇒ 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_exit ⇒ Boolean
81 82 83 84 85 |
# File 'lib/solid_objects/caller_process.rb', line 81 def stop_after_exit stop rescue false end |