Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created November 7, 2013 09:55
Show Gist options
  • Save JakubOboza/7352021 to your computer and use it in GitHub Desktop.
Save JakubOboza/7352021 to your computer and use it in GitHub Desktop.
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