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

Add streaming endpoints for Rails/Sinatra #186

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ruby/jruby-rails6/app/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Rails.application.routes.draw do
get "/slow", to: "tests#slow"
get "/error", to: "tests#error"
get "/streaming-error", to: "tests#streaming_error_in_body"
end
1 change: 1 addition & 0 deletions ruby/rails6-mongo/app/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

get "/slow", to: "tests#slow"
get "/error", to: "tests#error"
get "/streaming-error", to: "tests#streaming_error_in_body"

resources :posts, :except => %i[edit update destroy]
end
1 change: 1 addition & 0 deletions ruby/rails6-mysql/app/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Rails.application.routes.draw do
get "/slow", to: "tests#slow"
get "/error", to: "tests#error"
get "/streaming-error", to: "tests#streaming_error_in_body"

resources :posts, :except => %i[edit update destroy]
end
1 change: 1 addition & 0 deletions ruby/rails6-shoryuken/app/config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Rails.application.routes.draw do
get "/slow", to: "tests#slow"
get "/error", to: "tests#error"
get "/streaming-error", to: "tests#streaming_error_in_body"
get "/active_job_performance_job", to: "tests#active_job_performance_job"
get "/active_job_error_job", to: "tests#active_job_error_job"
root :to => "tests#index"
Expand Down
15 changes: 15 additions & 0 deletions ruby/rails7-delayed-job/app/app/controllers/examples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,19 @@ def slow
def error
raise "This is a Rails error!"
end

class StreamingBody
def each
yield "1"
sleep 0.5
yield "2"
yield "3"
raise "Rails error in streaming body"
end
end

def streaming_error_in_body
headers["Content-Length"] = "4"
response.body = StreamingBody.new
end
end
14 changes: 14 additions & 0 deletions ruby/rails7-goodjob/app/app/controllers/examples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,18 @@ def slow
def error
raise "This is a Rails error!"
end

class StreamingBody
def each
yield "1"
yield "2"
yield "3"
raise "Rails error in streaming body"
end
end

def streaming_error_in_body
headers["Content-Length"] = "4"
response.body = StreamingBody.new
end
end
1 change: 1 addition & 0 deletions ruby/rails7-goodjob/app/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
root :to => "examples#index"
get "/slow", to: "examples#slow"
get "/error", to: "examples#error"
get "/streaming-error", to: "examples#streaming_error_in_body"
end
15 changes: 15 additions & 0 deletions ruby/rails7-postgres/app/app/controllers/examples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,19 @@ def slow
def error
raise "This is a Rails error!"
end

class StreamingBody
def each
yield "1"
sleep 0.5
yield "2"
yield "3"
raise "Rails error in streaming body"
end
end

def streaming_error_in_body
headers["Content-Length"] = "4"
response.body = StreamingBody.new
end
end
1 change: 1 addition & 0 deletions ruby/rails7-postgres/app/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
root :to => "examples#index"
get "/slow", to: "examples#slow"
get "/error", to: "examples#error"
get "/streaming-error", to: "examples#streaming_error_in_body"
resources :items
end
15 changes: 15 additions & 0 deletions ruby/rails7-sequel/app/app/controllers/examples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,19 @@ def slow
def error
raise "This is a Rails error!"
end

class StreamingBody
def each
yield "1"
sleep 0.5
yield "2"
yield "3"
raise "Rails error in streaming body"
end
end

def streaming_error_in_body
headers["Content-Length"] = "4"
response.body = StreamingBody.new
end
end
1 change: 1 addition & 0 deletions ruby/rails7-sequel/app/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
root :to => "examples#index"
get "/slow", to: "examples#slow"
get "/error", to: "examples#error"
get "/streaming-error", to: "examples#streaming_error_in_body"
resources :users
end
15 changes: 15 additions & 0 deletions ruby/rails7-sidekiq/app/app/controllers/examples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ def error
raise "This is a Rails error!"
end

class StreamingBody
def each
yield "1"
sleep 0.5
yield "2"
yield "3"
raise "Rails error in streaming body"
end
end

def streaming_error_in_body
headers["Content-Length"] = "4"
response.body = StreamingBody.new
end

def error_reporter
Rails.error.handle do
1 + '1' # raises TypeError
Expand Down
1 change: 1 addition & 0 deletions ruby/rails7-sidekiq/app/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
root :to => "examples#index"
get "/slow", to: "examples#slow"
get "/error", to: "examples#error"
get "/streaming-error", to: "examples#streaming_error_in_body"
get "/error_reporter", to: "examples#error_reporter"
get "/queries", to: "examples#queries"
end
15 changes: 15 additions & 0 deletions ruby/rails7-solid-cache/app/app/controllers/examples_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,19 @@ def slow
def error
raise "This is a Rails error!"
end

class StreamingBody
def each
yield "1"
sleep 0.5
yield "2"
yield "3"
raise "Rails error in streaming body"
end
end

def streaming_error_in_body
headers["Content-Length"] = "4"
response.body = StreamingBody.new
end
end
1 change: 1 addition & 0 deletions ruby/rails7-solid-cache/app/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
root :to => "examples#index"
get "/slow", to: "examples#slow"
get "/error", to: "examples#error"
get "/streaming-error", to: "examples#streaming_error_in_body"
resources :items
end
10 changes: 10 additions & 0 deletions ruby/sinatra-puma/app/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ul>
<li><a href="/slow?time=#{time}">Slow request</a></li>
<li><a href="/error?time=#{time}">Error request</a></li>
<li><a href="/stream?time=#{time}">Streaming response</a></li>
</ul>
HTML
end
Expand All @@ -24,3 +25,12 @@
get "/error" do
raise "error"
end

get "/stream" do
stream do |out|
out << "a"
sleep 0.5
out << "b"
raise "Ouch"
end
end