Skip to content

enhancement: Generate OptimizelyConfig object on API Call instead of SDK initialization #296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/optimizely/config_manager/http_project_config_manager.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

#
# Copyright 2019-2020, Optimizely and contributors
# Copyright 2019-2020, 2022, Optimizely and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,7 +33,7 @@ module Optimizely
class HTTPProjectConfigManager < ProjectConfigManager
# Config manager that polls for the datafile and updated ProjectConfig based on an update interval.

attr_reader :stopped, :optimizely_config
attr_reader :stopped

# Initialize config manager. One of sdk_key or url has to be set to be able to use.
#
Expand Down Expand Up @@ -80,8 +80,8 @@ def initialize(
@last_modified = nil
@skip_json_validation = skip_json_validation
@notification_center = notification_center.is_a?(Optimizely::NotificationCenter) ? notification_center : NotificationCenter.new(@logger, @error_handler)
@optimizely_config = nil
@config = datafile.nil? ? nil : DatafileProjectConfig.create(datafile, @logger, @error_handler, @skip_json_validation)
@optimizely_config = @config.nil? ? nil : OptimizelyConfig.new(@config).config
@mutex = Mutex.new
@resource = ConditionVariable.new
@async_scheduler = AsyncScheduler.new(method(:fetch_datafile_config), @polling_interval, auto_update, @logger)
Expand Down Expand Up @@ -140,6 +140,12 @@ def config
@config
end

def optimizely_config
@optimizely_config = OptimizelyConfig.new(@config).config if @optimizely_config.nil?

@optimizely_config
end

private

def fetch_datafile_config
Expand Down Expand Up @@ -209,7 +215,9 @@ def set_config(config)
end

@config = config
@optimizely_config = OptimizelyConfig.new(config).config

# clearing old optimizely config so that a fresh one is generated on the next api call.
@optimizely_config = nil

@notification_center.send_notifications(NotificationCenter::NOTIFICATION_TYPES[:OPTIMIZELY_CONFIG_UPDATE])

Expand Down
11 changes: 8 additions & 3 deletions lib/optimizely/config_manager/static_project_config_manager.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

#
# Copyright 2019-2020, Optimizely and contributors
# Copyright 2019-2020, 2022, Optimizely and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,7 @@
module Optimizely
class StaticProjectConfigManager < ProjectConfigManager
# Implementation of ProjectConfigManager interface.
attr_reader :config, :optimizely_config
attr_reader :config

def initialize(datafile, logger, error_handler, skip_json_validation)
# Looks up and sets datafile and config based on response body.
Expand All @@ -40,8 +40,13 @@ def initialize(datafile, logger, error_handler, skip_json_validation)
error_handler,
skip_json_validation
)
@optimizely_config = nil
end

def optimizely_config
@optimizely_config = OptimizelyConfig.new(@config).config if @optimizely_config.nil?

@optimizely_config = @config.nil? ? nil : OptimizelyConfig.new(@config).config
@optimizely_config
end
end
end