Using Kiqit to Process the Existing Code to Background Process
Gem Sidekiq
provides an easy way to move some long and lengthy time consuming processes to be moved to background and make user experience better. Simply add gem "sidekiq"
to Gemfile
, run bundle install
and create some worker with the long lengthy code.
Before Sidekiq
1 2 3 4 5 6 7 8 9 |
|
After Sidekiq
1 2 3 4 5 6 7 |
|
1 2 3 4 5 6 7 |
|
This way the task is moved to be processed in background. Looks pretty simple, cool and easy.
Wait !! , But what if I have a bunch of them in no of models ??
- Copy code from model to a new worker for every method.
- Remove code from the models.
- Copy code from model to a new worker for every method.
This does’t look like a good approach. Here, kiqit
comes into the scenario and helps us to use the existing code without copy-pasting and creating new workers etc.
- Add gem "kiqit" to your rails Gemfile.
- Run bundle install
- Add the following line of code after some_time_consuming_task below the code ...
1 2 3 4 5 6 7 8 9 10 |
|
That ways, everything is handled the same way, as we would have by creating workers explicitly.