Search code examples
ruby-on-railsrubyherokusidekiqworker

How to share worker among two different applications on heroku?


I have two separate applications running on heroku and pointing to same database, first one responsible for user interfaceand second one for admin interface, I am using sidekiq with redis for background job processing, I have added one worker and I am able to share 'redis-server' by setting environment variable pointing to same Redis providing Addon, Now i wish to share worker too, because adding the extra worker will cost double.

Please suggest, whether this is even possible or not?


Solution

  • If both apps are using the same Redis URL and same namespace, you can spin up one worker with that same Redis config and it will be shared by both.

    Note that your Sidekiq process will boot one app or the other. The code for your Workers must be in that app. The other app won't be able to reference the code but can push jobs using:

    Sidekiq::Client.push('class' => 'SomeWorker', 'args' => [1,2,3])
    

    Note that 'class' is a String so SomeWorker can actually be defined in the other app.