In my rails app, I'm trying to move video uploading to a background task. I created a Sidekiq worker but need to render a JSON response at the end of the task (what I had previously done in the controller). For example, this is what the current controller looks like:
# start sidekiq worker
VideoUploaderWorker.perform_async(video_info)
respond_to do |format|
if @video.save
# add thumbnail image id to video
@video.update_attributes(:image_id=>@image.id)
# update project
@video.project.touch
format.js {
if params[:video]
render 'images/create'
else
logger.debug("sending JSON video id #{@video.id.to_json}")
video_info = @video.id, @video.video_path_url
render :json => video_info.to_json
end
}
else
Rails.logger "video save failed"
Rails.logger.info(@video.errors.inspect)
format.json { render :json => @video.errors, :status => :unprocessable_entity }
end
end
end
How can I render JSON from a sidekiq background job?