You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a better way than this if I want to inject a third party api client into the worker process? I have tried before_fork and after_fork hooks, but not working in my use case, because the api client will spawn child process to update its own cache from remote api. If I put Client.new in the main sneaker thread (or before/after fork), the cache updates do not get propagated to worker MyWorker processes. So, I resorted to code below, which seems to be working. But I am wondering if there's better ways?
classMyWorkerincludeSneakers::Workerattr_reader:my_clientdefinitialize(...)super(...)@my_client=Client.new(...)endfrom_queue'myworker'defwork(data)puts"executing at #{Time.now}"putsmy_client.method()ack!endend
The text was updated successfully, but these errors were encountered:
Is there a better way than this if I want to inject a third party api client into the worker process? I have tried
before_fork
andafter_fork
hooks, but not working in my use case, because the api client will spawn child process to update its own cache from remote api. If I putClient.new
in the main sneaker thread (orbefore
/after
fork), the cache updates do not get propagated to workerMyWorker
processes. So, I resorted to code below, which seems to be working. But I am wondering if there's better ways?The text was updated successfully, but these errors were encountered: