You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
'cleanup_old_experiments' error when running from non-web (eg. console) #715
The steps in the instructions in the "outside-of-a-web-session" are not working
I cloned the example project https://github.com/splitrb/split-rails-example
I have redis running and the sample page and dashboard work as expected.
Hopping into a rails console for that project and following the steps from #outside-of-a-web-session
it fails on trial.choose!
with error NoMethodError (undefined method `cleanup_old_experiments!' for nil:NilClass)
Looking at the code, it assumes that a Split::User is loaded.
It makes sense that some type of context and unique ID would need to be passed along when creating the new Trial instance, but just following the steps listed does not flow as expected. (unless there is something about an adapter that is required to make it work)
#- create a new experiment
experiment = Split::ExperimentCatalog.find_or_create('color', 'red', 'blue')
#- create a new trial
trial = Split::Trial.new(:experiment => experiment)
#- run trial
trial.choose! # << this will fail
The key part is to pass a user reference (and know how an existing user is identified)
key = "user-#{user.id}"
ab_user = Split::User.new(nil, Split::Persistence::RedisAdapter.new(nil, key))
trial = Split::Trial.new(user: ab_user, experiment: experiment) # << passing in the ab_user is the key
trial.choose! # << now this doesn't fail
The readme can just be updated with the part about initing a user reference to pass to Trial.new, then trial.choose! won't fail
Activity
jmccaffrey commentedon Sep 1, 2023
I had not seen the steps described in the wiki
https://github.com/splitrb/split/wiki/Use-Split-outside-a-web-request
The key part is to pass a user reference (and know how an existing user is identified)
key = "user-#{user.id}"
ab_user = Split::User.new(nil, Split::Persistence::RedisAdapter.new(nil, key))
The readme can just be updated with the part about initing a user reference to pass to Trial.new, then trial.choose! won't fail
andrehjr commentedon Sep 3, 2023
Hi @jmccaffrey thanks for the issue!
I fixed the readme on #716 it's also possible to load doing
Split::User.find(user_key, :redis)as a shortcut.