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

finished challenge #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
GEM
remote: https://rubygems.org/
specs:
coderay (1.1.2)
concurrent-ruby (1.0.5)
connection_pool (2.2.1)
httparty (0.15.6)
multi_xml (>= 0.5.2)
method_source (0.9.0)
multi_xml (0.6.0)
mustermann (1.0.1)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rack (2.0.3)
rack-protection (2.0.0)
rack
Expand All @@ -28,8 +33,9 @@ PLATFORMS

DEPENDENCIES
httparty
pry
sidekiq
sinatra

BUNDLED WITH
1.16.0
1.16.1
19 changes: 16 additions & 3 deletions client/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# screen.

response = HttpConnection.get('/')
puts # <fill this in>

puts JSON.parse(response)["message"]

##################################################
# Exercise 2: Extended interaction with a server
Expand All @@ -25,7 +24,17 @@
# C. Use `puts` to print the message portion of the response to the screen.

numbers = []
# <replace this with your code!>

loop do
number_response = JSON.parse(HttpConnection.get('/number'))
numbers << number_response["number"]
break if number_response["stop_asking"] == true
end

numbers_sum = numbers.reduce{|a, b| a + b}
message = HttpConnection.post('/sum', :body => {:the_sum => numbers_sum})

puts JSON.parse(message)["message"]

##################################################
# Exercise 3: Introducing sidekiq
Expand Down Expand Up @@ -57,8 +66,11 @@
# - Question to think about: why does all of this have to be this way?

# <insert first call here>
GetRequestSender.perform_async('/the_hard_stuff', by_using: 'a_sidekiq_worker!')
sleep 0.1

# <insert second call here>
GetRequestSender.perform_async('/the_easy_stuff', by_using: 'a_sidekiq_worker!')

verify_ex_4!

Expand All @@ -75,6 +87,7 @@
# (Remember to restart sidekiq after editing the file.)

# <code goes here>
GetRequestSender.perform_async('/touchy', by_using: 'a_sidekiq_worker!')

verify_ex_5! # This can take up to 30 seconds

Expand Down
6 changes: 6 additions & 0 deletions client/sidekiq_workers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ def perform(path, params={})
# For exercise 3, replace this comment with code that
# sends the request, parses the response, and uses `puts` to
# print the message part of the response
response = HttpConnection.get(path, :query => params)
puts JSON.parse(response)["message"]

# For exercise 5, replace this comment with code that
# retries the request if it fails
if response.code != 200
sleep 1
perform(path, params)
end
end
end