Created
March 27, 2013 16:50
-
-
Save sumskyi/5255941 to your computer and use it in GitHub Desktop.
want proper index
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
def pick(provider, current_proxy=nil) | |
_accessible = {"unaccessible" => nil} | |
_not_banned = [] | |
_not_banned << {"banned.#{provider}" => nil } | |
_not_banned << {"banned.#{provider}" => { '$lt' => BANNED_UNTIL[BANNED_SECONDS] }} | |
_different_subnet = {} | |
if current_proxy | |
_different_subnet = { | |
:subnet_int => {'$ne' => current_proxy[:subnet_int]} | |
} | |
end | |
_search_conditions = { | |
"$and" => [ | |
_accessible, | |
_different_subnet, | |
{'$or' => _not_banned } | |
] | |
} | |
_sort_conditions = {"used_at.#{provider}" => 1} | |
proxy = find_one(_search_conditions, :sort => _sort_conditions) | |
raise NoProxyLeft, "sorry, all proxies are banned by #{provider}" unless proxy | |
proxy[:used_at] ||= {} | |
proxy[:used_at][provider] = Time.now | |
proxy.update | |
proxy | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment