Commit 6e50040b authored by Matthias Käppler's avatar Matthias Käppler Committed by Bob Van Landuyt

Name all dameon threads

It is currently difficult to see what's running in a process
in e.g. `pstree`, since all threads spawned from a `Daemon`
are unnamed and appear as `dameon.rb:23`. I therefore added
a `name` method that has a sane default (snake case class)
and can be overridden if desired.
parent 72a963f0
......@@ -28,6 +28,10 @@ module Gitlab
true
end
def thread_name
self.class.name.demodulize.underscore
end
def start
return unless enabled?
......@@ -35,7 +39,10 @@ module Gitlab
break thread if thread?
if start_working
@thread = Thread.new { run_thread }
@thread = Thread.new do
Thread.current.name = thread_name
run_thread
end
end
end
end
......
......@@ -4,6 +4,7 @@ module Gitlab
module SidekiqDaemon
class Monitor < Daemon
include ::Gitlab::Utils::StrongMemoize
extend ::Gitlab::Utils::Override
NOTIFICATION_CHANNEL = 'sidekiq:cancel:notifications'
CANCEL_DEADLINE = 24.hours.seconds
......@@ -24,6 +25,11 @@ module Gitlab
@jobs_mutex = Mutex.new
end
override :thread_name
def thread_name
"job_monitor"
end
def within_job(worker_class, jid, queue)
jobs_mutex.synchronize do
jobs[jid] = { worker_class: worker_class, thread: Thread.current, started_at: Gitlab::Metrics::System.monotonic_time }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment