Module: LogStash::PluginMixins::Jdbc::Scheduler::JobDecorator

Defined in:
lib/logstash/plugin_mixins/jdbc/scheduler.rb

Instance Method Summary collapse

Instance Method Details

#start_work_threadObject



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/logstash/plugin_mixins/jdbc/scheduler.rb', line 138

def start_work_thread
  prev_thread_count = @scheduler.work_threads.size

  ret = super() # does not return Thread instance in 3.0

  work_threads = @scheduler.work_threads(:__all_no_cache__)
  while prev_thread_count == work_threads.size # very unlikely
    Thread.pass
    work_threads = @scheduler.work_threads(:__all_no_cache__)
  end

  work_thread_name_prefix = @scheduler.work_thread_name_prefix

  work_threads.sort! do |t1, t2|
    if t1[:name].nil?
      t2[:name].nil? ? 0 : +1 # nils at the end
    elsif t2[:name].nil?
      t1[:name].nil? ? 0 : -1
    else
      t1[:name] <=> t2[:name]
    end
  end

  work_threads.each_with_index do |thread, i|
    unless thread[:name]
      thread[:name] = "#{work_thread_name_prefix}#{sprintf('%02i', i)}"
      thread.name = thread[:name] if thread.respond_to?(:name=)
      # e.g. "[oracle]<jdbc_scheduler_worker-00"
    end
  end

  ret
end