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

Rupert sidekiq #1

Open
wants to merge 6 commits 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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ source "https://rubygems.org"
gem 'httparty'
gem 'sidekiq'
gem 'sinatra'
gem 'pry'
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
20 changes: 14 additions & 6 deletions client/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,27 @@
# screen.

response = HttpConnection.get('/')
puts # <fill this in>
puts JSON.parse(response)["message"]


##################################################
# Exercise 2: Extended interaction with a server
# The server has a big list of numbers. But it's not very good at math :-(, and
# it was hoping you could maybe help it sum them up.
# A. Send GET requests to /number until it tells you you've got them all.
# B. Send a POST to /sum with 'sum: <the sum>' as a parameter in the post body.
# B. Send a POST to /sum with 'the_sum: <sum>' as a parameter in the post body.
# C. Use `puts` to print the message portion of the response to the screen.

numbers = []
# <replace this with your code!>
loop do
response = HttpConnection.get('/number')
numbers << JSON.parse(response)["number"]
break if JSON.parse(response)["stop_asking"] == true
end

sum = numbers.reduce(:+)
response = HttpConnection.post('/sum', :body => { "the_sum" => sum})
puts JSON.parse(response)["message"]

##################################################
# Exercise 3: Introducing sidekiq
Expand Down Expand Up @@ -56,9 +64,9 @@
# Instead, it'll appear in the sidekiq terminal.
# - Question to think about: why does all of this have to be this way?

# <insert first call here>
GetRequestSender.perform_async('/the_hard_stuff')
sleep 0.1
# <insert second call here>
GetRequestSender.perform_async('/the_easy_stuff')

verify_ex_4!

Expand All @@ -74,7 +82,7 @@
#
# (Remember to restart sidekiq after editing the file.)

# <code goes here>
GetRequestSender.perform_async('/touchy')

verify_ex_5! # This can take up to 30 seconds

Expand Down
13 changes: 8 additions & 5 deletions client/sidekiq_workers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ class GetRequestSender
sidekiq_retry_in { 0 }

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
query = path + "?"
params.each do |k,v|
query += "&#{k}=#{v}"
end

# For exercise 5, replace this comment with code that
# retries the request if it fails
response = HttpConnection.get(query)
puts JSON.parse(response)["message"]

raise unless response.code == 200
end
end