Memcached servers changing leads to a tiny split-brain scenario since some servers might read from different caches then the others … good to keep an eye on it and alert when it happens too often. Here is a tiny snippet to report when it happens.
# Whenever the alive-ness of a server changes we read keys from a different server
# which leads to stale keys on the old server and cache-misses on the new servers
# so this should not happen often
# see lib/dalli/server.rb
# reproduce: rails c + Rails.cache.get + zdi memcached stop & start
$statsd.increment "dalli.connection_changed", tags: ["state:down"] unless @down_at
$statsd.increment "dalli.connection_changed", tags: ["state:up"] if @down_at
Symlinked vendor/bundle results in double load errors since:
- rails adds the realpath of each engines lib (and various other folders) to the $LOAD_PATH
- bundler adds the symlinked version to the $LOAD_PATH
- require_relative uses the realpath
which looks like: `already initialized constant Arturo::Middleware::MISSING_FEATURE_ERROR`
- bundle install –path vendor/bundle
- mv vendor/bundle tmp
- cd vendor && ln -s ../tmp/bundle bundle
- enable eager_load + preload_frameworks in config/environment/development.rb
- rails runner 1
linked_bundle = File.expand_path(Bundler.bundle_path)
real_bundle = File.realpath(Bundler.bundle_path)
if linked_bundle != real_bundle
$LOAD_PATH.each_with_index do |path, i|
$LOAD_PATH[i] = path.sub(linked_bundle, real_bundle)
A simple solution to an annoying problem!
task "assets:precompile" => "db:migrate" if ENV['MIGRATE_ON_PRECOMPILE']
# run to enable
heroku config:set MIGRATE_ON_PRECOMPILE=1
Compare 2 objects without having to repeat all their variables and potentially miss something, only thing dangerous is adding something like a inline method cache, which would then break equality.
self.class == other.class && instance_variables.all? do |i|
instance_variable_get(i) == other.instance_variable_get(i)
We don’t want to compile assets during test runs, since that is slow, but we also don’t want the asset pipeline to fail because assets are missing.
Rails 5.1 added a flag for this which prints deprecations and will be removed in rails 5.2 so that is not a elegant solution either.
config.assets.unknown_asset_fallback = true
So we are now using this fix to fake assets being available!:
# make our tests fast by avoiding asset compilation
# but do not raise when assets are not compiled either
Rails.application.config.assets.compile = false
def resolve_asset_path(path, *)
super || path