Skip to content
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

Not receiving recommendations #7

Closed
bhardin opened this issue Feb 13, 2012 · 103 comments
Closed

Not receiving recommendations #7

bhardin opened this issue Feb 13, 2012 · 103 comments
Labels

Comments

@bhardin
Copy link

bhardin commented Feb 13, 2012

Whenever I call, current_user.recommendations, I always receive a blank list.

@davidcelis
Copy link
Owner

Can you verify that your current_user has liked or disliked at least one thing? If current_user hasn't rated anything, they'll get no recommendations. Likewise, if there are no other users in the system (or nobody has rated anything yet), nobody will have recommendations.

@bhardin
Copy link
Author

bhardin commented Feb 13, 2012

Yes, there are two users on the system. Both of which have likes (current_user.liked) and dislikes (current_user.dislikes).

I am running on heroku, and I am curious about the command

QUEUE=recommendable rake environment resque:work

How can I verify that heroku is spinning up recommendable?

@davidcelis
Copy link
Owner

Heroku uses Redis To Go. Unless you set up your Redis instance as per their instructions, there's essentially no Redis connection: http://blog.redistogo.com/2010/07/26/resque-with-redis-to-go/

@bhardin
Copy link
Author

bhardin commented Feb 13, 2012

I've setup RedisToGo and have it configured. I didn't know how to check the status of recommendable to see if there is anything in the queue it is trying to consume.

@davidcelis
Copy link
Owner

Could you gist your recommendable initializer?

@bhardin
Copy link
Author

bhardin commented Feb 13, 2012

https://gist.github.com/1821282

The REDIS_TOGO Env variable is setup on heroku using:

heroku config:add REDISTOGO_URL='URL'

with the URL being what I get from the redistogo details.

@davidcelis
Copy link
Owner

What is the result of

$ heroku console Recommendable.redis.inspect
$ heroku console Resque.inspect

@bhardin
Copy link
Author

bhardin commented Feb 13, 2012

$ heroku console Recommendable.redis.inspect
"#<Redis client v2.2.2 connected to redis://chubb.redistogo.com:9156/0 (Redis v2.4.6)>"
$ heroku console Resque.inspect
"Resque Client connected to redis://chubb.redistogo.com:9156/0"

@davidcelis
Copy link
Owner

Check the queue size:

$ heroku console
>> Resque.size(:recommendable)

@bhardin
Copy link
Author

bhardin commented Feb 13, 2012

$ heroku console
Ruby console for myapp.heroku.com
>> Resque.size(:recommendable)
=> 7

Looks like they are queued, but not being consumed.

@davidcelis
Copy link
Owner

Hot. My guess is it may have something to do with Heroku's naming of their rake tasks. The link I pasted above had this code block:

require 'resque/tasks'

task "resque:setup" => :environment do
  ENV['QUEUE'] = '*'
end

desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"

It looks like you have to do that alias. This block should go in lib/tasks/resque.rake

@bhardin
Copy link
Author

bhardin commented Feb 13, 2012

Edited lib/tasks/resque.rake with that code block. But doesn't looks like it is working.

$ heroku console Resque.size :recommendable
7

@bhardin
Copy link
Author

bhardin commented Feb 13, 2012

So out of curiousity I attempted to run

$ heroku rake resque:work QUEUE=*

which is in the same tutorial, but higher up. When executing to check on my queue, I am now down to 5. However, that command is obviously not returning and isn't a long term solution. Let me see if it completes and returns.

@davidcelis
Copy link
Owner

Is your Procfile configured correctly to automatically call this command upon boot? The following line should be in there:

worker: QUEUE=recommendable [bundle exec] rake resque:work

(bundle exec may or may not be needed depending on your configuration)

@bhardin
Copy link
Author

bhardin commented Feb 13, 2012

I'm on the bamboo stack, not the cedar stack. Looks like I probably need to roll over. So I will go ahead and update. Let you know what happens after.

@bhardin
Copy link
Author

bhardin commented Feb 14, 2012

I have rolled everything over to the Cedar stack. Still having the same issue. It looks like the queue is getting filled, but nothing is grabbing them.

I have attempted to modify my procfile from both:

worker: QUEUE=recommendable bundle exec rake resque:work

and

worker: QUEUE=recommendable rake resque:work

EDIT: Heroku definitely sees the procfile and worker... Console says the following:

-----> Discovering process types
       Procfile declares types      -> worker
       Default types for Ruby/Rails -> console, rake, web
-----> Compiled slug size is 26.9MB
-----> Launching... done, v18

@davidcelis
Copy link
Owner

what about rake environment resque:work?

@bhardin
Copy link
Author

bhardin commented Feb 14, 2012

Upon running heroku run rake environment resque:work it emptied the queue. Can I put that command into my Procfile?

@davidcelis
Copy link
Owner

Emptied the queue? Like, your queue is just fuggin' gone (I'm so sorry), or the jobs got processed?

@bhardin
Copy link
Author

bhardin commented Feb 14, 2012

Before executing rake enviornement reqsque:work, The Resque.size :recommendable returned 2. After issuing heroku run rake environment reque:work, the same command returned 0.

> Resque.size :recommendable
=> 0

Jobs, look processed... But it still doesn't look like I have recommendations.

@davidcelis
Copy link
Owner

Assuming your model is User, and the current_user has an ID of one, can you tell me what the following returns:

$ heroku console
>> Recommendable.redis.zcard "User:1:similarities"

@bhardin
Copy link
Author

bhardin commented Feb 14, 2012

irb(main):015:0> Recommendable.redis.zcard "User:1:similarities"
=> 2

@davidcelis
Copy link
Owner

Recommendable.redis.zrangebyscore("User:1:similarities", -1, 1).map do |user|
  Recommendable.redis.zscore "User:1:similarities", user
end

Also, what version of Recommendable are you using?

@bhardin
Copy link
Author

bhardin commented Feb 14, 2012

Recommendable.redis.zrangebyscore("User:1:similarities", -1, 1).map do |user|
irb(main):038:1*   Recommendable.redis.zscore "User:1:similarities", user
irb(main):039:1> end
=> ["0", "0"]

version 0.1.4

@davidcelis
Copy link
Owner

Looks like the similarity values are, indeed, not being calculated correctly. I'll look into this.

@bhardin
Copy link
Author

bhardin commented Feb 14, 2012

Word. Thanks.

@davidcelis
Copy link
Owner

However, the recommendations themselves are still generating locally for me, so it's strange that you're getting an empty array.

@davidcelis
Copy link
Owner

Wow. Well, the similarity bug is extremely obvious now that I see it. Still unsure of your empty recommendations array, though. Let me patch this up and we'll see if that, for some reason, fixes that for you.

@davidcelis
Copy link
Owner

Update to 0.1.5 and let me know if your problem persists.

Please, please, please read the CHANGELOG, though. There's a migration you'll need to run.

Also, keep in mind that Recommendable isn't going to work well with the Nano (smallest) Redis To Go instance. You'll need, at the least, the 20 MB Mini instance. Nano is not persistent.

@bhardin
Copy link
Author

bhardin commented Feb 14, 2012

Did Recommendable work with Nano before version 0.1.5?

@Kelend
Copy link

Kelend commented Mar 19, 2012

irb(main):037:0> User.find(1).recommendations User Load (2.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", 1]] (1.1ms) SELECT COUNT(*) FROM "recommendable_likes" WHERE "recommendable_likes"."user_id" = 1 (1.1ms) SELECT COUNT(*) FROM "recommendable_dislikes" WHERE "recommendable_dislikes"."user_id" = 1 => []

@davidcelis
Copy link
Owner

I don't suppose you can run those COUNT(*) selects manually from a DB console on heroku?

@blackgold9
Copy link

You sure can
result = ActiveRecord::Base.connection.select_all( “select satemetn here″ )

On Mon, Mar 19, 2012 at 2:59 PM, David Celis <
reply@reply.github.com

wrote:

I don't suppose you can run those COUNT(*) selects manually from a DB
console on heroku?


Reply to this email directly or view it on GitHub:
#7 (comment)

@Kelend
Copy link

Kelend commented Mar 20, 2012

(131.1ms) SELECT COUNT(*) FROM "recommendable_likes" WHERE "recommendable_likes"."user_id" = 1 => [{"count"=>"16"}]
(18.9ms) SELECT COUNT(*) FROM "recommendable_dislikes" WHERE "recommendable_dislikes"."user_id" = 1 => [{"count"=>"0"}]

@blackgold9
Copy link

that looks good...
Is your redis plan the permanent one? Can you generate recs locally?

@Kelend
Copy link

Kelend commented Mar 24, 2012

Sorry for the delay in responding, got called into another project. Permanent redis plan, and recommendations are generating fine locally.

@davidcelis
Copy link
Owner

@Kelend, are you using PostgreSQL locally as well, or just on Heroku?

@Kelend
Copy link

Kelend commented Mar 26, 2012

@davidcelis locally is sqlite, mysql works fine too, I've been having issues getting postgreSQL set up on my local environment

@davidcelis
Copy link
Owner

Interesting. I'm going to go ahead and set up a new app using PostgreSQL as the database and see what happens. It could very well be some sort of incompatibility between the queries I've written and postgres; this would explain the Heroku problems. I'll let you know how that goes.

@bhardin
Copy link
Author

bhardin commented Apr 10, 2012

Sorry for not responding sooner. First time I have been able to work back on this project. After setting up redis and a redis front end, I see the same error as @Kelend

uninitialized constant Restaurant::
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/inheritance.rb:119:in `compute_type'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/reflection.rb:172:in `klass'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/associations/association.rb:117:in `klass'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/associations/association.rb:165:in `find_target?'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/associations/collection_association.rb:332:in `load_target'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/associations/collection_proxy.rb:44:in `load_target'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/associations/collection_proxy.rb:88:in `method_missing'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/bundler/gems/recommendable-5dd278a40ab8/lib/recommendable/acts_as_recommendable.rb:113:in `create_liked_by_set'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/bundler/gems/recommendable-5dd278a40ab8/lib/recommendable/acts_as_recommendable.rb:68:in `create_recommendable_sets'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/bundler/gems/recommendable-5dd278a40ab8/lib/recommendable/acts_as_recommended_to.rb:634:in `predict'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/bundler/gems/recommendable-5dd278a40ab8/lib/recommendable/acts_as_recommended_to.rb:618:in `block in update_recommendations_for'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/relation/batches.rb:21:in `block (2 levels) in find_each'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/relation/batches.rb:21:in `each'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/relation/batches.rb:21:in `block in find_each'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/relation/batches.rb:72:in `find_in_batches'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/relation/batches.rb:20:in `find_each'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/gems/activerecord-3.2.0/lib/active_record/querying.rb:8:in `find_each'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/bundler/gems/recommendable-5dd278a40ab8/lib/recommendable/acts_as_recommended_to.rb:616:in `update_recommendations_for'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/bundler/gems/recommendable-5dd278a40ab8/lib/recommendable/acts_as_recommended_to.rb:607:in `block in update_recommendations'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/bundler/gems/recommendable-5dd278a40ab8/lib/recommendable/acts_as_recommended_to.rb:607:in `each'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/bundler/gems/recommendable-5dd278a40ab8/lib/recommendable/acts_as_recommended_to.rb:607:in `update_recommendations'
/Users/bhardin/.rvm/gems/ruby-1.9.3-p0/bundler/gems/recommendable-5dd278a40ab8/app/workers/recommendable/recommendation_refresher.rb:9:in `perform'

Obviously mine is on restaurants. Any fix for this? This is running locally on sqlite3

@bhardin
Copy link
Author

bhardin commented Apr 10, 2012

note: When I issue the command, User.first.send :update_recommendations in console, the recommendations are created.

@davidcelis
Copy link
Owner

No fix for this yet because I have no idea why the error comes up. It happens for me only through Resque now, and anything in the console works. I'm stumped. I've verified that my resque worker is loading the environment correctly, so it shouldn't be getting uninitialized constants.

@Kelend
Copy link

Kelend commented Apr 11, 2012

Its working locally for me with the mysql2 adapter, broke using sqlite3 & pg with the same uninitialized constant error

@bhardin
Copy link
Author

bhardin commented Apr 11, 2012

@davidcelis Are you using mysql locally? If so, if you change to sqlite what happens?

@davidcelis
Copy link
Owner

Oh shit. I was also switching between PSQL and SQLite. I'll try MySQL later tonight.

@Kelend
Copy link

Kelend commented Apr 11, 2012

Solved the uninitialized constant for me by modifying acts_as_recommendable.rb
has_many :liked_by, :through => :likes, :source => :user, :foreign_key => :user_id, :class_name => Recommendable.user_class.to_s
has_many :disliked_by, :through => :dislikes, :source => :user, :foreign_key => :user_id, :class_name => Recommendable.user_class.to_s

I can get this to process update_recommendations on sqlite3, mysql, and postgres(on heroku)

I'm still having an issue with getting it to process in the background through Resque, but I think thats a seperate issue (my jobs aren't getting persisted into Redis)

@davidcelis
Copy link
Owner

@Kelend: ❤️

Would you mind opening a separate issue for that if you think it's related to Recommendable? You've seemed to solve this, and your current issue doesn't sound related to the UninitializedConstant.

Pushing up a fix to this horrible, horrible error now.

@bhardin
Copy link
Author

bhardin commented Apr 11, 2012

Are you going to bundle this into 0.1.7 and push? Want to check out this awesomeness.

@davidcelis
Copy link
Owner

It's a shitty enough bug that I could and probably should. I was hoping to switch the app over to using Sidekiq instead of Resque, however, so if you'd give me a bit of time to do that first, you can instead point your Gemfile to the git repo instead of then.

The change to using Sidekiq has been several weeks coming, as Resque is barely maintained anymore.

@davidcelis
Copy link
Owner

@bhardin Done. Make sure to check the changelog and edit your initializer as needed. Resque is gone, and Sidekiq is here to stay.

@bhardin
Copy link
Author

bhardin commented Apr 11, 2012

So, it is now only using Sidekiq and Resque no longer? The initalizer needs to change. Correct?

I saw from your previous message that it was going to take a while to change over to Sidekiq. Is this no longer the case? Can you give an example of what the initializer needs to look now?

@bhardin
Copy link
Author

bhardin commented Apr 11, 2012

I was able to handle the initializer scripts for the app to kick off. I am now having a challenge running: bundle exec sidekiq -q recommendable

It looks like it is trying to startup a local redis server instead of using the server I specified.

2012-04-11T20:07:41Z 48401 TID-zrrt3o INFO: Booting sidekiq 1.0.0 with Redis at localhost:6379
2012-04-11T20:07:41Z 48401 TID-zrrt3o INFO: Running in ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin10.8.0]
2012-04-11T20:07:41Z 48401 TID-zrrt3o ERROR: Manager#processor_died died
Connection refused - Unable to connect to Redis on localhost:6379

@davidcelis
Copy link
Owner

The new templated initializer can be found here: https://github.com/davidcelis/recommendable/blob/master/lib/generators/recommendable/templates/initializer.rb

There is a commented out block to configure the Redis connection that Sidekiq will use. It assumes localhost:6379 unless specified, or unless REDISTOGO_URL is specified for Heroku.

@davidcelis
Copy link
Owner

unfortunately, I just had to revert the commit with Sidekiq included, at least for now. I failed to realize that the license was GPL and I would rather not have to license Recommendable under the GPL due to a GPL dependency. Sorry for this brief confusion, but it's back to Resque.

@bhardin
Copy link
Author

bhardin commented Apr 11, 2012

No problem. Totally understand the licensing dealo. Will revert back to resque.

@romaind
Copy link

romaind commented Apr 14, 2012

Hi there,

Sorry to bother but I can't figure out how to make .recommendations work in my local environment. It keeps returning [].
Everything else works but .recommendations.
My redis/resque setup seems to be ok and similar_raters works well.

I've forked the project and added the foreign keys in acts_as_recommendable.rb just like blackgold9 said but it still won't work !

Did I forget something ?

@davidcelis
Copy link
Owner

@romaind Are you using the most up-to-date version of Recommendable? Or pointing at the github repo?

@romaind
Copy link

romaind commented Apr 14, 2012

I'm pointing at the github repo in my Gemfile

@davidcelis
Copy link
Owner

@romaind Please open up a new issue on here and describe the problem. Any code/errors you're getting will be helpful. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants