In sidekiq's log file, I can see IDs of workers, like this:
2013-08-28T10:19:03Z 8911 TID-osy5fnl1o MyWorker JID-262996c2737e7a5ec5c71674 INFO: start
2013-08-28T10:19:03Z 8911 TID-ptes4 MyWorker JID-6830e08b5da72b360d4d1ae2 INFO: start
2013-08-28T10:19:03Z 8911 TID-povog MyWorker JID-2d31755b001ecd02fe1abc09 INFO: done: 22.52 sec
2013-08-28T10:19:04Z 8911 TID-povog MyWorker JID-df52f500a3ba27e18b2ba313 INFO: start
Inside the body of my worker's @perform@ method, I'd like to get that ID. If not possible, what would be the best strategy to get a unique ID for that worker, taking into consideration that there are multiple concurrent workers of the same class?
I need this for help in processing log files.
You can access the job id using the jid accessor method and the thread id using the Thread.current method. Like this:
logger.info "JID #{jid} - TID #{Thread.current.object_id.to_s(36)}"
If you're using ActiveJob
you get get it with self.job_id
(or @job_id
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With