Class: DevCycle::LocalBucketing
- Inherits:
-
Object
- Object
- DevCycle::LocalBucketing
- Extended by:
- T::Sig
- Defined in:
- lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb
Constant Summary collapse
- @@rand =
Random.new(seed = Random.new_seed)
- @@engine =
Wasmtime::Engine.new
- @@wasmmodule =
Wasmtime::Module.from_file(@@engine, "#{__dir__}/bucketing-lib.release.wasm")
- @@wasi_ctx =
Wasmtime::WasiCtxBuilder.new .inherit_stdout .inherit_stderr .set_argv(ARGV) .set_env(ENV)
- @@store =
Wasmtime::Store.new(@@engine, wasi_ctx: @@wasi_ctx)
- @@linker =
Wasmtime::Linker.new(@@engine, wasi: true)
- @@stack_tracer =
lambda {}
- @@instance =
@@linker.instantiate(@@store, @@wasmmodule)
- @@memory =
@@instance.export("memory").to_memory
Instance Attribute Summary collapse
-
#has_config ⇒ Object
Returns the value of attribute has_config.
-
#initialized ⇒ Object
Returns the value of attribute initialized.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #check_event_queue_size ⇒ Object
- #close ⇒ Object
- #flush_event_queue ⇒ Object
- #generate_bucketed_config(user) ⇒ Object
- #init_event_queue(options) ⇒ Object
-
#initialize(sdkkey, options, wait_for_init) ⇒ LocalBucketing
constructor
A new instance of LocalBucketing.
- #on_payload_failure(payload_id, retryable) ⇒ Object
- #on_payload_success(payload_id) ⇒ Object
- #queue_aggregate_event(event, bucketeduser) ⇒ Object
- #queue_event(user, event) ⇒ Object
- #set_client_custom_data(customdata) ⇒ Object
- #store_config(config) ⇒ Object
Constructor Details
#initialize(sdkkey, options, wait_for_init) ⇒ LocalBucketing
Returns a new instance of LocalBucketing.
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 88 def initialize(sdkkey, , wait_for_init) @initialized = false @has_config = false @sdkkey = sdkkey = @logger = .logger set_sdk_key_internal(sdkkey) platform_data = PlatformData.new('server', VERSION, RUBY_VERSION, nil, 'Ruby', Socket.gethostname) set_platform_data(platform_data) @config_manager = ConfigManager.new(@sdkkey, self, wait_for_init) end |
Instance Attribute Details
#has_config ⇒ Object
Returns the value of attribute has_config.
17 18 19 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 17 def has_config @has_config end |
#initialized ⇒ Object
Returns the value of attribute initialized.
16 17 18 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 16 def initialized @initialized end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
15 16 17 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 15 def end |
Instance Method Details
#check_event_queue_size ⇒ Object
136 137 138 139 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 136 def check_event_queue_size @@stack_tracer = lambda { || raise } @@instance.invoke("eventQueueSize", @sdkKeyAddr) end |
#close ⇒ Object
100 101 102 103 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 100 def close @config_manager.close @config_manager = nil end |
#flush_event_queue ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 123 def flush_event_queue @@stack_tracer = lambda { || raise } payload_addr = @@instance.invoke("flushEventQueue", @sdkKeyAddr) raw_json = read_asc_string(payload_addr) raw_payloads = Oj.load(raw_json) if raw_payloads == nil return [] end raw_payloads.map { |raw_payload| EventsPayload.new(raw_payload["records"], raw_payload["payloadId"], raw_payload["eventCount"]) } end |
#generate_bucketed_config(user) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 106 def generate_bucketed_config(user) user_addr = malloc_asc_string(user.to_json) @@stack_tracer = lambda { || raise } config_addr = @@instance.invoke("generateBucketedConfigForUser", @sdkKeyAddr, user_addr) bucketed_config_json = read_asc_string(config_addr) bucketed_config_hash = Oj.load(bucketed_config_json) BucketedUserConfig.new(bucketed_config_hash['project'], bucketed_config_hash['environment'], bucketed_config_hash['features'], bucketed_config_hash['featureVariationMap'], bucketed_config_hash['variableVariationMap'], bucketed_config_hash['variables'], bucketed_config_hash['knownVariableKeys']) end |
#init_event_queue(options) ⇒ Object
195 196 197 198 199 200 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 195 def init_event_queue() = Oj.dump() = malloc_asc_string() @@stack_tracer = lambda { || raise } @@instance.invoke("initEventQueue", @sdkKeyAddr, ) end |
#on_payload_failure(payload_id, retryable) ⇒ Object
181 182 183 184 185 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 181 def on_payload_failure(payload_id, retryable) payload_addr = malloc_asc_string(payload_id) @@stack_tracer = lambda { || raise } @@instance.invoke("onPayloadFailure", @sdkKeyAddr, payload_addr, retryable ? 1 : 0) end |
#on_payload_success(payload_id) ⇒ Object
142 143 144 145 146 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 142 def on_payload_success(payload_id) payload_addr = malloc_asc_string(payload_id) @@stack_tracer = lambda { || raise } @@instance.invoke("onPayloadSuccess", @sdkKeyAddr, payload_addr) end |
#queue_aggregate_event(event, bucketeduser) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 162 def queue_aggregate_event(event, bucketeduser) begin variable_variation_map = if !bucketeduser.nil? bucketeduser.variable_variation_map else {} end varmap_addr = malloc_asc_string(Oj.dump(variable_variation_map)) asc_pin(varmap_addr) event_addr = malloc_asc_string(Oj.dump(event)) @@stack_tracer = lambda { || raise } @@instance.invoke("queueAggregateEvent", @sdkKeyAddr, event_addr, varmap_addr) ensure asc_unpin(varmap_addr) end end |
#queue_event(user, event) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 149 def queue_event(user, event) begin user_addr = malloc_asc_string(Oj.dump(user)) asc_pin(user_addr) event_addr = malloc_asc_string(Oj.dump(event)) @@stack_tracer = lambda { || raise } @@instance.invoke("queueEvent", @sdkKeyAddr, user_addr, event_addr) ensure asc_unpin(user_addr) end end |
#set_client_custom_data(customdata) ⇒ Object
203 204 205 206 207 208 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 203 def set_client_custom_data(customdata) customdata_json = Oj.dump(customdata) customdata_addr = malloc_asc_string(customdata_json) @@stack_tracer = lambda { || raise } @@instance.invoke("setClientCustomData", customdata_addr) end |
#store_config(config) ⇒ Object
188 189 190 191 192 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 188 def store_config(config) config_addr = malloc_asc_string(config) @@stack_tracer = lambda { || raise } @@instance.invoke("setConfigData", @sdkKeyAddr, config_addr) end |