toptal / chewy

High-level Elasticsearch Ruby framework based on the official elasticsearch-ruby client
MIT License
1.88k stars 366 forks source link

LazySidekiq strategy #827

Closed sl4vr closed 2 years ago

sl4vr commented 2 years ago

This PR implements proof of concept for new Chewy strategy. The strategy allows to avoid synchronous evaluation of index queries. Instead all the callbacks will be saved in class attribute and model type and id will be stashed into strategy instance. When strategy block ends it will enqueue IndicesUpdateWorker Sidekiq job with serialized stash as argument. The job will load records and run all the callbacks within sidekiq strategy block, which in turn will enqueue Sidekiq jobs updating indices. Since we cannot schedule IndicesUpdateWorker job for destroyed records, instead all the callbacks will be run synchronously and resulted index types and ids will be stashed into strategy instance and run on the lazy_sidekiq strategy block end like if they would be run on the end of sidekiq strategy block.

Some concerns to consider:


Before submitting the PR make sure the following are checked: