Access a value on all threads in the Rails application


I have a user model and i am setting a value in a thread

Thread.current[:partner_domain] = ""

I am able to access this in model, but not in delayed job worker, as it runs in separate thread, i can't save this domain in my database due to some business requirement.

To be more clear i am using Thread.current[:partner_domain] in a dynamically created method, that is being invoked by delayed job worker

Please help me with this.

Multithreading has nothing to do with this. DelayedJob worker runs in a separate process and, as such, doesn't share anything with your rails server process. Not threads, not memory, nothing.

The right thing to do would be to bundle all the data the job needs into its arguments. Something like this:

 MyClass.delay.do_action(primary_data, options)

Where options contain your partner domain name and all the other info. Then the job just accesses the info from the arguments.