Comments (4)
I also faced same issue with Unicorn server. Worker processes use same file for backup and throw error as posted by creator of this issue. The potential workaround is to set different backup file for each worker process:
after_worker_ready do |server, worker|
app_name = Unleash.configuration.app_name
Unleash.configuration.backup_file = Dir.tmpdir + "/unleash-#{app_name}-#{worker.nr}-repo.json"
::UNLEASH = Unleash::Client.new
end
from unleash-client-ruby.
Just to make everything work for puma clustered/single modes, sidekiq, rails console & other libs I did next config like a workaround:
in lib/unleash.rb
# frozen_string_literal: true
require "unleash"
require "socket"
require "securerandom"
require "forwardable"
module UNLEASH
FakeClient = Struct.new(:turn_on) do
def enabled?(*)
turn_on
end
def if_enabled(*)
yield if turn_on
end
def shutdown; end
def shutdown!; end
end
class << self
extend Forwardable
def_delegators :client,
:enabled?,
:if_enabled,
:get_variant,
:shutdown,
:shutdown!
def preload
@client = if ENV.fetch("UNLEASH_TOKEN", nil) && ENV.fetch("UNLEASH_URL", nil)
Unleash::Client.new(
app_name: "#{ENV.fetch("DD_SERVICE", nil)}-#{SecureRandom.uuid}",
environment: ENV.fetch("DD_ENV", nil),
instance_id: Socket.gethostname,
url: ENV.fetch("UNLEASH_URL", nil),
custom_http_headers: { Authorization: ENV.fetch("UNLEASH_TOKEN", nil) }
)
else
FakeClient.new(false)
end
end
def client
@client || preload
end
end
end
in puma.rb
require_relative File.expand_path("../lib/unleash.rb", __dir__) # if not --preload
# unleash
on_worker_boot do
UNLEASH.preload
end
on_worker_shutdown do
UNLEASH.shutdown
end
in config/initializers/unleash.rb
require_relative File.expand_path("../../lib/unleash.rb", __dir__)
Rails.application.console do
UNLEASH.preload
end
Sidekiq.configure_server do |config|
config.on(:startup) do
UNLEASH.preload
end
config.on(:shutdown) do
UNLEASH.shutdown
end
end
So now I can call UNLEASH.enabled?("some feature")
in any place, and it will work (Unleash::Client will be initialized in a lazy way).
In puma
, sidekiq
, rails c
I do preload the client to avoid some delay on the initial call.
in RSpec
it is disabled by default because my test env does not have credentials ENV vars. I can allow(UNLEASH).to receive(:enabled?).with("some feature").and_return(true)
if I want to make sure the test works well with enabled/disabled feature.
from unleash-client-ruby.
But such configuration looks awful, so would be great to find some more convenient way of unleash
client configuration.
from unleash-client-ruby.
I also faced same issue with Unicorn server. Worker processes use same file for backup and throw error as posted by creator of this issue. The potential workaround is to set different backup file for each worker process:
after_worker_ready do |server, worker| app_name = Unleash.configuration.app_name Unleash.configuration.backup_file = Dir.tmpdir + "/unleash-#{app_name}-#{worker.nr}-repo.json" ::UNLEASH = Unleash::Client.new end
Thanks for this, I've also got it working in the worker boot block
on_worker_boot do |index|
Unleash.configuration.backup_file = Dir.tmpdir + "/unleash-#{index}-repo.json"
Rails.configuration.unleash = Unleash::Client.new
end
from unleash-client-ruby.
Related Issues (20)
- Default environment variables for connection values HOT 3
- Implement Global Segments
- Constraint and Strategy Order of Operations May be Wrong HOT 1
- Provide a #to_h method for Unleash::Context HOT 1
- Variants in bootstrap file not respected when client is disabled. HOT 3
- When client is disabled, but metrics are not, metrics are referenced but never initialized.
- Strategy variants HOT 1
- context_value in Constraint#matches_constraint? throws FrozenError when fronzen-string-literal magic comment is true in the calling context HOT 1
- feat: Backoff based on http statuses HOT 1
- Add featureEnabled to variant response
- fix: default intervals HOT 1
- fix: metrics only sent if not empty HOT 2
- feat: Add support for boostrap HOT 2
- Release v4.0.0. What is the braking change? HOT 3
- feat: add support for dynamic headers
- feat: Add support for global fallback function HOT 3
- Extend tests for bootstrapping priority HOT 1
- Review/redesign/refactor ScheduledExecutor HOT 1
- Support semantic versioning for releases HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from unleash-client-ruby.