hedgesky
hedgesky

Reputation: 3311

How to make Sidekiq workers not to load Rails environment

My Rails app starts a Sidekiq worker that only sends text messages. I am sure it doesn't need whole Rails env to work (it takes only client's phone and text to send as params). But currently the worker loads it and thus grabs a lot of memory from my tiny DigitalOcean droplet (as like separate Rails application).

Is there any way to tell the worker path to the only file it should require?

Upvotes: 4

Views: 910

Answers (2)

Mike Perham
Mike Perham

Reputation: 22228

You can use -r to require a file rather than boot Rails.

Upvotes: 3

Anthony
Anthony

Reputation: 15967

You can completely decouple your sidekiq worker to be standalone (one or two files) and run that as a separate process on your digital ocean instance. Then in your rails app when you're ready for work to be done you'd just push a job into redis:

Sidekiq::Client.push({
    'class' => TextMessageWorker,
    'queue' => queue_name,
    'args'  => [number, message]
})

There are obvious limitations to that (no scheduling AFAIK) but that should meet your needs for this small example.

Upvotes: 3

Related Questions