Plugin Helper: Thread
The thread plugin helper manages threads and these threads are integrated with plugins. No need for manual run or shutdown in the plugin.
Here is an example:
require 'fluent/plugin/output'
module Fluent::Plugin
class ExampleOutput < Output
Fluent::Plugin.register_output('example', self)
# 1. Load thread helper
helpers :thread
# Omit `configure`, `shutdown` and other plugin APIs
def start
super
# 2. Create and run thread with unique name.
thread_create(:example_thread_run, &method(:run))
end
def run
# ...
end
end
end
The launched thread is managed by the plugin helper. No need of thread shutdown code in plugin's shutdown method. It shutdowns the launched threads automatically.