Class: Vapey::VapeyController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Vapey::VapeyController
- Defined in:
- app/controllers/vapey/vapey_controller.rb
Instance Method Summary collapse
Instance Method Details
#healthcheck ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/vapey/vapey_controller.rb', line 4 def healthcheck vapey = Vapey::Search.new begin # Send a PING command to Redis redis_ping_response = vapey.redis.ping # Check if the Redis server responded with "PONG" if redis_ping_response == 'PONG' # create the index if it's not already there vapey.create_index else render json: { status: 'unhealthy', message: 'Redis connection is unhealthy' } end rescue Redis::CommandError, Redis::CannotConnectError => e if e. == "Index already exists" render json: { status: 'healthy', message: 'Redis connection is healthy' } else render json: { status: 'unhealthy', message: "Redis connection error: #{e.}" } end end end |
#search ⇒ Object
28 29 30 31 32 |
# File 'app/controllers/vapey/vapey_controller.rb', line 28 def search vapey = Vapey::Search.new result = vapey.(params[:embedding]) render json: result end |
#upsert ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/vapey/vapey_controller.rb', line 34 def upsert vapey = Vapey::Search.new # Hopefully don't have to do this ## json_params = JSON.parse(request.raw_post) # Extract the key and value from the request data id = params[:id] # Upsert the record into the Redis database vapey.redis.json_set("item:#{id}", Rejson::Path.root_path, params.deep_stringify_keys) # Return a success response render json: { status: 'success', message: "Record upserted successfully", key: "item:#{id}" } end |