Commit 403cdd7c authored by Michael Rose's avatar Michael Rose

api: stories: return 404+json, reindex if >2w old

parent 945b4477
......@@ -4,16 +4,23 @@ class Api::V1::StoriesController < ApplicationController
respond_to :json
def show
respond_with(@story)
if @story.nil?
render json: {status: 'not_found', message: "Story(#{@id}) not found and couldn't be retrieved." }, status: 404
else
respond_with(@story)
end
end
private
def set_story
@story = Story.find_by(id: params[:id])
@id = params[:id]
@story = Story.find_by(id: @id)
if @story == nil
FetchAndIndexWorker.new.perform(params[:id])
@story = Story.find_by(id: params[:id])
FetchAndIndexWorker.new.perform(@id)
@story = Story.find_by(id: @id)
elsif @story.last_seen < 2.weeks.ago
FetchAndIndexWorker.perform_async(@id)
end
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment