Closed matteeyah closed 1 year ago
rails-settings-cached has solved this problem:
https://github.com/huacnlee/rails-settings-cached/commit/0849bb203e46ba58663ff55288e2589ab501f210
The in-memory cache only enables in Web application process, because by this commit changes, is enabled by a Rails middleware, that now enable in background worker (Sidekiq).
You have not given me the details, which cache storage did you use for? (Redis?)
For example:
Storage cache in Redis.
Web
will fetch settings from Redis cache (if not exist, fallback to database).Worker A
will fetch Redis cache (if not exist, fallback to database).Worker B
will get settings directly from Redis cache (because it wrote by Worker A
) You have not given me the details, which cache storage did you use for? (Redis?)
The environment in which we were testing wasn't using Redis as the cache store. It used a file store (which was obviously different for every node). Switching to Redis solved this.
Thanks for the help!
Summary
Acutal
If I have two application nodes, one is the web worker, and the other one is a background worker, the following happens:
Maybe sidekiq doesn't process every single job as a new "request" and does some sort of "pooling" or long request 🤔
Expected
Workaround
Clear cache before performing each background job with
System
I'm using
ActiveJob
withSidekiq
as a backend.