Module: Proxied::Nosql::ProxyMethods::ClassMethods
- Defined in:
- lib/proxied/nosql/proxy_methods.rb
Instance Method Summary collapse
- #get_random_proxy(protocol: :all, proxy_type: :all, category: nil, maximum_failed_attempts: nil, retries: 3) ⇒ Object
- #get_valid_proxies(protocol: :all, proxy_type: :all, category: nil, maximum_failed_attempts: nil) ⇒ Object
- #should_be_checked(mode: :synchronous, protocol: :all, proxy_type: :all, category: nil, date: Time.now, limit: nil, maximum_failed_attempts: 10) ⇒ Object
Instance Method Details
#get_random_proxy(protocol: :all, proxy_type: :all, category: nil, maximum_failed_attempts: nil, retries: 3) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/proxied/nosql/proxy_methods.rb', line 43 def get_random_proxy(protocol: :all, proxy_type: :all, category: nil, maximum_failed_attempts: nil, retries: 3) proxies = get_valid_proxies(protocol: protocol, proxy_type: proxy_type, category: category, maximum_failed_attempts: maximum_failed_attempts) proxies = yield(proxies) if block_given? proxy = nil begin proxy = proxies.skip(rand(proxies.count)).first rescue StandardError retries -= 1 retry if retries > 0 end return proxy end |
#get_valid_proxies(protocol: :all, proxy_type: :all, category: nil, maximum_failed_attempts: nil) ⇒ Object
37 38 39 40 41 |
# File 'lib/proxied/nosql/proxy_methods.rb', line 37 def get_valid_proxies(protocol: :all, proxy_type: :all, category: nil, maximum_failed_attempts: nil) proxies = get_proxies(protocol: protocol, proxy_type: proxy_type, category: category) proxies = proxies.where(valid_proxy: true) proxies = proxies.where(:failed_attempts.lte => maximum_failed_attempts) if maximum_failed_attempts end |
#should_be_checked(mode: :synchronous, protocol: :all, proxy_type: :all, category: nil, date: Time.now, limit: nil, maximum_failed_attempts: 10) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/proxied/nosql/proxy_methods.rb', line 14 def should_be_checked(mode: :synchronous, protocol: :all, proxy_type: :all, category: nil, date: Time.now, limit: nil, maximum_failed_attempts: 10) proxies = get_proxies(protocol: protocol, proxy_type: proxy_type, category: category) proxies = proxies.where(checkable: true) proxies = proxies.where(asyncable: true) if mode.to_sym.eql?(:asynchronous) proxies = proxies.any_of( {:last_checked_at.exists => false}, {:last_checked_at.ne => nil}, {:last_checked_at.exists => true, :last_checked_at.ne => nil, :last_checked_at.lt => date} ) proxies = proxies.any_of( {:failed_attempts.exists => false}, {:failed_attempts.in => ["", nil]}, {:failed_attempts.exists => true, :failed_attempts.nin => ["", nil], :failed_attempts.lte => maximum_failed_attempts} ) proxies = proxies.order_by([[:valid_proxy, :asc], [:failed_attempts, :asc], [:last_checked_at, :asc]]) proxies = proxies.limit(limit) if limit && !limit.zero? return proxies end |