Skip to content

Instantly share code, notes, and snippets.

@bleonard
Created April 14, 2017 22:03
Show Gist options
  • Save bleonard/bc04bffc3a1d8d0c91da205fa813d26b to your computer and use it in GitHub Desktop.
Save bleonard/bc04bffc3a1d8d0c91da205fa813d26b to your computer and use it in GitHub Desktop.
class UserIndexWorker
include TResque::Worker
inputs :user_id
def work
Elasticsearch.index('users').write(user.attributes.slice(:id, :first_name, :last_name, :etc))
end
def user
@user ||= User.find(user_id)
end
end
# When user changes
UserIndexWorker.enqueue(user_id: user.id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment