mirror of
https://github.com/discourse/discourse.git
synced 2026-08-11 13:35:20 -05:00
FEATURE: Allow plugins to register demon processes (#11493)
This allows plugins to call `register_demon_process` with a Class inheriting from Demon::Base. The unicorn master process will take care of spawning, monitoring and restarting the process. This API should be used with extreme caution, but it is significantly cleaner than spawning processes/threads in an `after_initialize` block. This commit also cleans up the demon spawning logging so that it uses the same format as unicorn worker logging. It also switches to the block form of `fork` to ensure that Demons exit after running, rather than returning execution to where the fork took place.
This commit is contained in:
+6
-8
@@ -141,15 +141,13 @@ class Demon::Base
|
||||
end
|
||||
|
||||
def run
|
||||
if @pid = fork
|
||||
write_pid_file
|
||||
return
|
||||
@pid = fork do
|
||||
Process.setproctitle("discourse #{self.class.prefix}")
|
||||
monitor_parent
|
||||
establish_app
|
||||
after_fork
|
||||
end
|
||||
|
||||
Process.setproctitle("discourse #{self.class.prefix}")
|
||||
monitor_parent
|
||||
establish_app
|
||||
after_fork
|
||||
write_pid_file
|
||||
end
|
||||
|
||||
def already_running?
|
||||
|
||||
@@ -68,6 +68,7 @@ class DiscoursePluginRegistry
|
||||
define_register :vendored_pretty_text, Set
|
||||
define_register :vendored_core_pretty_text, Set
|
||||
define_register :seedfu_filter, Set
|
||||
define_register :demon_processes, Set
|
||||
|
||||
define_filtered_register :staff_user_custom_fields
|
||||
define_filtered_register :public_user_custom_fields
|
||||
|
||||
@@ -861,6 +861,15 @@ class Plugin::Instance
|
||||
), self)
|
||||
end
|
||||
|
||||
# Register a new demon process to be forked by the Unicorn master.
|
||||
# The demon_class should inherit from Demon::Base.
|
||||
# With great power comes great responsibility - this method should
|
||||
# be used with extreme caution. See `config/unicorn.conf.rb`.
|
||||
def register_demon_process(demon_class)
|
||||
raise "Not a demon class" if !demon_class.ancestors.include?(Demon::Base)
|
||||
DiscoursePluginRegistry.demon_processes << demon_class
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def self.js_path
|
||||
|
||||
Reference in New Issue
Block a user