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
-
#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(sdkkey, config) ⇒ Object
Constructor Details
#initialize(sdkkey, options, wait_for_init) ⇒ LocalBucketing
Returns a new instance of LocalBucketing.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 87 def initialize(sdkkey, , wait_for_init) @initialized = false @sdkkey = sdkkey @options = @logger = .logger platform_data = PlatformData.new('server', VERSION, RUBY_VERSION, nil, 'Ruby', Socket.gethostname) set_platform_data(platform_data) @configmanager = ConfigManager.new(@sdkkey, self, wait_for_init) end |
Instance Attribute Details
#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 @options end |
Instance Method Details
#check_event_queue_size ⇒ Object
135 136 137 138 139 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 135 def check_event_queue_size sdkkey_addr = malloc_asc_string(@sdkkey) @@stack_tracer = lambda { || raise } @@instance.invoke("eventQueueSize", sdkkey_addr) end |
#close ⇒ Object
98 99 100 101 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 98 def close @configmanager.close @configmanager = nil end |
#flush_event_queue ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 121 def flush_event_queue sdkkey_addr = malloc_asc_string(@sdkkey) @@stack_tracer = lambda { || raise } payload_addr = @@instance.invoke("flushEventQueue", sdkkey_addr) 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
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 104 def generate_bucketed_config(user) sdkkey_addr = malloc_asc_string(@sdkkey) user_addr = malloc_asc_string(user.to_json) @@stack_tracer = lambda { || raise } config_addr = @@instance.invoke("generateBucketedConfigForUser", sdkkey_addr, 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
190 191 192 193 194 195 196 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 190 def init_event_queue() = Oj.dump() sdkkey_addr = malloc_asc_string(@sdkkey) = malloc_asc_string() @@stack_tracer = lambda { || raise } @@instance.invoke("initEventQueue", sdkkey_addr, ) end |
#on_payload_failure(payload_id, retryable) ⇒ Object
174 175 176 177 178 179 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 174 def on_payload_failure(payload_id, retryable) sdkkey_addr = malloc_asc_string(@sdkkey) payload_addr = malloc_asc_string(payload_id) @@stack_tracer = lambda { || raise } @@instance.invoke("onPayloadFailure", sdkkey_addr, payload_addr, retryable ? 1 : 0) end |
#on_payload_success(payload_id) ⇒ Object
142 143 144 145 146 147 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 142 def on_payload_success(payload_id) sdkkey_addr = malloc_asc_string(@sdkkey) payload_addr = malloc_asc_string(payload_id) @@stack_tracer = lambda { || raise } @@instance.invoke("onPayloadSuccess", sdkkey_addr, payload_addr) end |
#queue_aggregate_event(event, bucketeduser) ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 159 def queue_aggregate_event(event, bucketeduser) sdkkey_addr = malloc_asc_string(@sdkkey) variable_variation_map = if !bucketeduser.nil? bucketeduser.variable_variation_map else {} end varmap_addr = malloc_asc_string(Oj.dump(variable_variation_map)) event_addr = malloc_asc_string(Oj.dump(event)) @@stack_tracer = lambda { || raise } @@instance.invoke("queueAggregateEvent", sdkkey_addr, event_addr, varmap_addr) end |
#queue_event(user, event) ⇒ Object
150 151 152 153 154 155 156 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 150 def queue_event(user, event) sdkkey_addr = malloc_asc_string(@sdkkey) user_addr = malloc_asc_string(Oj.dump(user)) event_addr = malloc_asc_string(Oj.dump(event)) @@stack_tracer = lambda { || raise } @@instance.invoke("queueEvent", sdkkey_addr, user_addr, event_addr) end |
#set_client_custom_data(customdata) ⇒ Object
199 200 201 202 203 204 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 199 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(sdkkey, config) ⇒ Object
182 183 184 185 186 187 |
# File 'lib/devcycle-ruby-server-sdk/localbucketing/local_bucketing.rb', line 182 def store_config(sdkkey, config) sdkkey_addr = malloc_asc_string(sdkkey) config_addr = malloc_asc_string(config) @@stack_tracer = lambda { || raise } @@instance.invoke("setConfigData", sdkkey_addr, config_addr) end |