Documentation
¶
Overview ¶
Package spawner provides interfaces and implementations for auto-spawning worker containers/functions when jobs are created.
Supported spawners:
- Docker: Spawns local Docker containers
- Swarm: Spawns Docker Swarm services (for Dokploy)
- Lambda: Triggers AWS Lambda functions
Index ¶
- type Config
- type DockerConfig
- type DockerSpawner
- func (s *DockerSpawner) ActiveCount() int
- func (s *DockerSpawner) CleanupCompleted(ctx context.Context) error
- func (s *DockerSpawner) Close() error
- func (s *DockerSpawner) Name() string
- func (s *DockerSpawner) Spawn(ctx context.Context, req *SpawnRequest) (*SpawnResult, error)
- func (s *DockerSpawner) Status(ctx context.Context, workerID string) (*SpawnResult, error)
- func (s *DockerSpawner) Stop(ctx context.Context, workerID string) error
- type LambdaConfig
- type LambdaPayload
- type LambdaSpawner
- func (s *LambdaSpawner) ActiveCount() int
- func (s *LambdaSpawner) CleanupOld()
- func (s *LambdaSpawner) Close() error
- func (s *LambdaSpawner) MarkCompleted(workerID string)
- func (s *LambdaSpawner) MarkFailed(workerID string)
- func (s *LambdaSpawner) Name() string
- func (s *LambdaSpawner) Spawn(ctx context.Context, req *SpawnRequest) (*SpawnResult, error)
- func (s *LambdaSpawner) Status(ctx context.Context, workerID string) (*SpawnResult, error)
- func (s *LambdaSpawner) Stop(ctx context.Context, workerID string) error
- type NoOpSpawner
- func (s *NoOpSpawner) Close() error
- func (s *NoOpSpawner) Name() string
- func (s *NoOpSpawner) Spawn(ctx context.Context, req *SpawnRequest) (*SpawnResult, error)
- func (s *NoOpSpawner) Status(ctx context.Context, workerID string) (*SpawnResult, error)
- func (s *NoOpSpawner) Stop(ctx context.Context, workerID string) error
- type SpawnRequest
- type SpawnResult
- type Spawner
- type SpawnerType
- type SwarmConfig
- type SwarmSpawner
- func (s *SwarmSpawner) ActiveCount() int
- func (s *SwarmSpawner) CleanupCompleted(ctx context.Context) error
- func (s *SwarmSpawner) Close() error
- func (s *SwarmSpawner) Name() string
- func (s *SwarmSpawner) Spawn(ctx context.Context, req *SpawnRequest) (*SpawnResult, error)
- func (s *SwarmSpawner) Status(ctx context.Context, workerID string) (*SpawnResult, error)
- func (s *SwarmSpawner) Stop(ctx context.Context, workerID string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Type is the spawner type to use
Type SpawnerType
// ManagerURL is the URL workers should connect to
ManagerURL string
// RabbitMQURL is the message queue URL
RabbitMQURL string
// RedisAddr is the Redis address
RedisAddr string
// Proxies is the proxy URL for workers (e.g., "socks5://host:port")
Proxies string
// Docker-specific configuration
Docker DockerConfig
// Swarm-specific configuration (Dokploy)
Swarm SwarmConfig
// Lambda-specific configuration
Lambda LambdaConfig
}
Config holds configuration for spawner initialization
type DockerConfig ¶
type DockerConfig struct {
// Image is the Docker image to use for workers
Image string
// Network is the Docker network to attach workers to
Network string
// Concurrency is the default concurrency per worker
Concurrency int
// AutoRemove removes containers after they exit
AutoRemove bool
// MaxWorkers is the maximum number of concurrent workers (0 = unlimited)
MaxWorkers int
// Environment variables to pass to workers
Environment map[string]string
}
DockerConfig holds Docker spawner configuration
type DockerSpawner ¶
type DockerSpawner struct {
// contains filtered or unexported fields
}
DockerSpawner spawns workers as local Docker containers
func NewDockerSpawner ¶
func NewDockerSpawner(cfg *DockerConfig, managerURL, rabbitmqURL, redisAddr, proxies string) (*DockerSpawner, error)
NewDockerSpawner creates a new Docker spawner
func (*DockerSpawner) ActiveCount ¶
func (s *DockerSpawner) ActiveCount() int
ActiveCount returns the number of active containers
func (*DockerSpawner) CleanupCompleted ¶
func (s *DockerSpawner) CleanupCompleted(ctx context.Context) error
CleanupCompleted removes tracking for containers that have exited
func (*DockerSpawner) Close ¶
func (s *DockerSpawner) Close() error
func (*DockerSpawner) Name ¶
func (s *DockerSpawner) Name() string
func (*DockerSpawner) Spawn ¶
func (s *DockerSpawner) Spawn(ctx context.Context, req *SpawnRequest) (*SpawnResult, error)
func (*DockerSpawner) Status ¶
func (s *DockerSpawner) Status(ctx context.Context, workerID string) (*SpawnResult, error)
type LambdaConfig ¶
type LambdaConfig struct {
// FunctionName is the Lambda function name or ARN
FunctionName string
// Region is the AWS region
Region string
// InvocationType is "Event" (async) or "RequestResponse" (sync)
InvocationType string
// MaxConcurrent is the maximum concurrent Lambda invocations
MaxConcurrent int
}
LambdaConfig holds AWS Lambda spawner configuration
type LambdaPayload ¶
type LambdaPayload struct {
JobID string `json:"job_id"`
Priority int `json:"priority"`
ManagerURL string `json:"manager_url"`
RabbitMQURL string `json:"rabbitmq_url,omitempty"`
RedisAddr string `json:"redis_addr,omitempty"`
Concurrency int `json:"concurrency,omitempty"`
}
LambdaPayload is the payload sent to the Lambda function
type LambdaSpawner ¶
type LambdaSpawner struct {
// contains filtered or unexported fields
}
LambdaSpawner spawns workers by invoking AWS Lambda functions
func NewLambdaSpawner ¶
func NewLambdaSpawner(cfg *LambdaConfig, managerURL, rabbitmqURL, redisAddr string) (*LambdaSpawner, error)
NewLambdaSpawner creates a new AWS Lambda spawner
func (*LambdaSpawner) ActiveCount ¶
func (s *LambdaSpawner) ActiveCount() int
ActiveCount returns the number of active invocations
func (*LambdaSpawner) CleanupOld ¶
func (s *LambdaSpawner) CleanupOld()
CleanupOld removes old invocation tracking entries
func (*LambdaSpawner) Close ¶
func (s *LambdaSpawner) Close() error
func (*LambdaSpawner) MarkCompleted ¶
func (s *LambdaSpawner) MarkCompleted(workerID string)
MarkCompleted marks an invocation as completed This should be called when the worker reports job completion
func (*LambdaSpawner) MarkFailed ¶
func (s *LambdaSpawner) MarkFailed(workerID string)
MarkFailed marks an invocation as failed
func (*LambdaSpawner) Name ¶
func (s *LambdaSpawner) Name() string
func (*LambdaSpawner) Spawn ¶
func (s *LambdaSpawner) Spawn(ctx context.Context, req *SpawnRequest) (*SpawnResult, error)
func (*LambdaSpawner) Status ¶
func (s *LambdaSpawner) Status(ctx context.Context, workerID string) (*SpawnResult, error)
type NoOpSpawner ¶
type NoOpSpawner struct{}
NoOpSpawner is a spawner that does nothing (for when auto-spawn is disabled)
func (*NoOpSpawner) Close ¶
func (s *NoOpSpawner) Close() error
func (*NoOpSpawner) Name ¶
func (s *NoOpSpawner) Name() string
func (*NoOpSpawner) Spawn ¶
func (s *NoOpSpawner) Spawn(ctx context.Context, req *SpawnRequest) (*SpawnResult, error)
func (*NoOpSpawner) Status ¶
func (s *NoOpSpawner) Status(ctx context.Context, workerID string) (*SpawnResult, error)
type SpawnRequest ¶
type SpawnRequest struct {
// JobID is the UUID of the job to process
JobID uuid.UUID
// Priority of the job (higher = more urgent)
Priority int
// ManagerURL is the URL workers should connect to
ManagerURL string
// RabbitMQURL is the message queue URL
RabbitMQURL string
// RedisAddr is the Redis address for queue/cache
RedisAddr string
// Concurrency is the number of concurrent scrapers per worker
Concurrency int
// WorkerImage is the Docker image to use (for Docker/Swarm spawners)
WorkerImage string
// ExtraArgs are additional arguments to pass to the worker
ExtraArgs []string
}
SpawnRequest contains the information needed to spawn a worker
type SpawnResult ¶
type SpawnResult struct {
// WorkerID is the identifier of the spawned worker (container ID, task ARN, etc.)
WorkerID string
// Status is the current status of the spawn operation
Status string
// Error message if spawn failed
Error string
}
SpawnResult contains the result of a spawn operation
type Spawner ¶
type Spawner interface {
// Spawn starts a new worker to process a job
Spawn(ctx context.Context, req *SpawnRequest) (*SpawnResult, error)
// Status checks the status of a spawned worker
Status(ctx context.Context, workerID string) (*SpawnResult, error)
// Stop terminates a spawned worker
Stop(ctx context.Context, workerID string) error
// Close cleans up spawner resources
Close() error
// Name returns the spawner type name
Name() string
}
Spawner is the interface for spawning workers on-demand
type SpawnerType ¶
type SpawnerType string
SpawnerType represents the type of spawner
const ( SpawnerTypeNone SpawnerType = "none" SpawnerTypeDocker SpawnerType = "docker" SpawnerTypeSwarm SpawnerType = "swarm" SpawnerTypeLambda SpawnerType = "lambda" )
type SwarmConfig ¶
type SwarmConfig struct {
// Image is the Docker image to use for workers
Image string
// Network is the overlay network to attach workers to
Network string
// Concurrency is the default concurrency per worker
Concurrency int
// Replicas is the number of replicas per service
Replicas int
// MaxServices is the maximum number of concurrent services
MaxServices int
// Labels to apply to spawned services
Labels map[string]string
// Constraints for service placement
Constraints []string
// Environment variables to pass to workers
Environment map[string]string
}
SwarmConfig holds Docker Swarm spawner configuration (for Dokploy)
type SwarmSpawner ¶
type SwarmSpawner struct {
// contains filtered or unexported fields
}
SwarmSpawner spawns workers as Docker Swarm services This is ideal for Dokploy deployments where Swarm manages the cluster
func NewSwarmSpawner ¶
func NewSwarmSpawner(cfg *SwarmConfig, managerURL, rabbitmqURL, redisAddr string) (*SwarmSpawner, error)
NewSwarmSpawner creates a new Docker Swarm spawner
func (*SwarmSpawner) ActiveCount ¶
func (s *SwarmSpawner) ActiveCount() int
ActiveCount returns the number of active services
func (*SwarmSpawner) CleanupCompleted ¶
func (s *SwarmSpawner) CleanupCompleted(ctx context.Context) error
CleanupCompleted removes services that have completed
func (*SwarmSpawner) Close ¶
func (s *SwarmSpawner) Close() error
func (*SwarmSpawner) Name ¶
func (s *SwarmSpawner) Name() string
func (*SwarmSpawner) Spawn ¶
func (s *SwarmSpawner) Spawn(ctx context.Context, req *SpawnRequest) (*SpawnResult, error)
func (*SwarmSpawner) Status ¶
func (s *SwarmSpawner) Status(ctx context.Context, workerID string) (*SpawnResult, error)