简体   繁体   中英

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?

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.

您可以使用-r来请求文件而不是引导Rails。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM