Module: ScraperUtils::RandomizeUtils
- Defined in:
- lib/scraper_utils/randomize_utils.rb
Overview
Provides utilities for randomizing processing order in scrapers, particularly helpful for distributing load and avoiding predictable patterns
Class Method Summary collapse
-
.randomize_order(collection) ⇒ Array
Returns a randomized version of the input collection when in production mode, or the original collection when in test/sequential mode.
-
.sequential=(value) ⇒ Boolean?
Explicitly set sequential mode for testing.
-
.sequential? ⇒ Boolean
Checks if sequential processing is enabled.
Class Method Details
.randomize_order(collection) ⇒ Array
Returns a randomized version of the input collection when in production mode, or the original collection when in test/sequential mode
12 13 14 15 16 |
# File 'lib/scraper_utils/randomize_utils.rb', line 12 def self.randomize_order(collection) return collection.to_a if sequential? collection.to_a.shuffle end |
.sequential=(value) ⇒ Boolean?
Explicitly set sequential mode for testing
30 31 32 |
# File 'lib/scraper_utils/randomize_utils.rb', line 30 def self.sequential=(value) @sequential = value end |
.sequential? ⇒ Boolean
Checks if sequential processing is enabled
21 22 23 24 |
# File 'lib/scraper_utils/randomize_utils.rb', line 21 def self.sequential? @sequential = !ENV["MORPH_PROCESS_SEQUENTIALLY"].to_s.empty? if @sequential.nil? @sequential || false end |