Created
November 7, 2013 09:55
-
-
Save JakubOboza/7352021 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lets assume you have array or urls yes ? | |
urls.each do |url| | |
check_if_counter < 50 | |
if yes | |
spawn_thread(url) | |
else | |
sleep(2) | |
retry | |
end | |
end | |
possibly try_fetch_url needs to be a function with it like this | |
def try_fetch_url(url) | |
if counter < THREAD_CAP | |
try_update_counter | |
if updated | |
spawn_thread(url) | |
else | |
sleep(2) | |
try_fetch_url(url) | |
end | |
else | |
sleep(2) | |
try_fetch_url(url) | |
end | |
end | |
or | |
def try_fetch_url(url) | |
while(true) do | |
if counter < COUNTER_CAP | |
increment_counter | |
spawn_thread(url) | |
else | |
sleep(1) | |
end | |
end | |
end | |
with spawn thread like this | |
def spawn_thread(url) | |
Thread.new do | |
perform_job | |
decrement_counter | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment