Documentation
¶
Index ¶
- type CircuitBreaker
- type Crawler
- type HostRateLimiter
- type KafkaEnhancedCrawler
- func (kec *KafkaEnhancedCrawler) BatchEnqueueURLs(ctx context.Context, urls []string, priority string, source string) error
- func (kec *KafkaEnhancedCrawler) Close() error
- func (kec *KafkaEnhancedCrawler) EnqueueURL(ctx context.Context, url string) error
- func (kec *KafkaEnhancedCrawler) EnqueueURLWithPriority(ctx context.Context, url string, priority string, source string) error
- func (kec *KafkaEnhancedCrawler) StartEnhanced(ctx context.Context)
- type RobotsCache
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CircuitBreaker ¶
type CircuitBreaker struct {
// contains filtered or unexported fields
}
CircuitBreaker implements the circuit breaker pattern for hosts
func NewCircuitBreaker ¶
func NewCircuitBreaker( failureThreshold float64, resetTimeout time.Duration, succRequiredToClose int, rollingWindowSize int, hostErrorExpiry time.Duration, ) *CircuitBreaker
NewCircuitBreaker creates a new circuit breaker
func (*CircuitBreaker) GetState ¶
func (cb *CircuitBreaker) GetState(host string) string
GetState returns the current state of the circuit for a host
func (*CircuitBreaker) IsAllowed ¶
func (cb *CircuitBreaker) IsAllowed(host string) bool
IsAllowed checks if requests are allowed for the host
func (*CircuitBreaker) RecordFailure ¶
func (cb *CircuitBreaker) RecordFailure(host string)
RecordFailure records a failed request to the host
func (*CircuitBreaker) RecordSuccess ¶
func (cb *CircuitBreaker) RecordSuccess(host string)
RecordSuccess records a successful request to the host
func (*CircuitBreaker) Reset ¶
func (cb *CircuitBreaker) Reset(host string)
Reset resets the circuit for a host to closed state
type Crawler ¶
type Crawler struct {
// contains filtered or unexported fields
}
Crawler manages the crawling process
func NewCrawler ¶
func NewCrawler(cfg *config.Config, q queue.Queue, s database.Storage, m *metrics.MetricsCollector, p *proxy.Manager) (*Crawler, error)
NewCrawler creates a new Crawler instance
func (*Crawler) EnqueueURL ¶
EnqueueURL adds a URL to the queue for crawling
type HostRateLimiter ¶
type HostRateLimiter struct {
// contains filtered or unexported fields
}
HostRateLimiter manages rate limits for different hosts
func NewHostRateLimiter ¶
func NewHostRateLimiter(defaultQPS float64, defaultRPS int) *HostRateLimiter
NewHostRateLimiter creates a new rate limiter for hosts defaultQPS is requests per second (e.g., 0.2 for one request per 5 seconds) defaultRPS is burst capacity (max requests allowed at once)
func (*HostRateLimiter) Allow ¶
func (h *HostRateLimiter) Allow(host string) bool
Allow reports whether an event may happen for the host Does not block, but rather reports if rate limit would allow
type KafkaEnhancedCrawler ¶
type KafkaEnhancedCrawler struct {
*Crawler // Embed the basic crawler
// contains filtered or unexported fields
}
KafkaEnhancedCrawler extends the basic crawler with Kafka event sourcing and advanced features
func NewKafkaEnhancedCrawler ¶
func NewKafkaEnhancedCrawler(cfg *config.Config, q queue.Queue, s database.Storage, m *metrics.MetricsCollector, p *proxy.Manager) (*KafkaEnhancedCrawler, error)
NewKafkaEnhancedCrawler creates a new Kafka-enhanced crawler
func (*KafkaEnhancedCrawler) BatchEnqueueURLs ¶
func (kec *KafkaEnhancedCrawler) BatchEnqueueURLs(ctx context.Context, urls []string, priority string, source string) error
BatchEnqueueURLs enqueues multiple URLs efficiently using Kafka batch publishing
func (*KafkaEnhancedCrawler) Close ¶
func (kec *KafkaEnhancedCrawler) Close() error
Close closes the enhanced crawler and Kafka producer
func (*KafkaEnhancedCrawler) EnqueueURL ¶
func (kec *KafkaEnhancedCrawler) EnqueueURL(ctx context.Context, url string) error
EnqueueURL enqueues a URL with priority support and event tracking
func (*KafkaEnhancedCrawler) EnqueueURLWithPriority ¶
func (kec *KafkaEnhancedCrawler) EnqueueURLWithPriority(ctx context.Context, url string, priority string, source string) error
EnqueueURLWithPriority enqueues a URL with specific priority and source tracking
func (*KafkaEnhancedCrawler) StartEnhanced ¶
func (kec *KafkaEnhancedCrawler) StartEnhanced(ctx context.Context)
StartEnhanced starts the enhanced crawler with Kafka features
type RobotsCache ¶
type RobotsCache struct {
// contains filtered or unexported fields
}
RobotsCache caches robots.txt files and provides access control methods
func NewRobotsCache ¶
func NewRobotsCache(userAgent string, client *http.Client) *RobotsCache
NewRobotsCache creates a new robots.txt cache with the given user agent