mirror of
https://github.com/warmbly/warmbly.git
synced 2026-08-19 00:01:14 +00:00
73cabf6f5e
Workers emit a WorkerHealth event every 30s with assigned mailbox count, IMAP IDLE connections, memory, goroutines, and rolling 1h send/bounce/ complaint/auth-error/rate-limit counters. Consumer writes them to worker_health_samples. Schema additions on workers: egress_kind (cold_smtp / oauth_api / warmup_only), health_state (healthy / watch / throttled / quarantined / blocked), load_score (weighted utilization). worker_capacity_view aggregates the latest hour of samples into a per-worker capacity row used by the assignment loop. Effective capacity = base_ceiling(egress_kind) × health_multiplier × age_ramp_multiplier so a fresh worker earns its way up to base capacity over 72h, and a worker with rising bounces or complaints automatically gets less load. MailboxWeight returns 1.0 for cold_smtp, 0.05 for Gmail/Graph API (worker IP doesn't matter), 0.4 for warmup-only. AssignWorkerToEmail resolves the mailbox's weight and SelectSharedWorker filters by headroom + sorts by utilization, so a 200-mailbox OAuth worker and a 16-mailbox cold worker balance fairly. UnassignWorkerFromEmail refunds the load_score symmetrically.
67 lines
2.8 KiB
Go
67 lines
2.8 KiB
Go
package models
|
|
|
|
type WorkerEventType string
|
|
|
|
const (
|
|
WorkerEventTypeSendEmail WorkerEventType = "SEND_EMAIL"
|
|
WorkerEventTypeAddEmail WorkerEventType = "ADD_EMAIL"
|
|
WorkerEventTypeRemoveEmail WorkerEventType = "REMOVE_EMAIL"
|
|
WorkerEventTypeEmailValidation WorkerEventType = "EMAIL_VALIDATION"
|
|
WorkerEventTypeWarmupAction WorkerEventType = "WARMUP_ACTION"
|
|
)
|
|
|
|
type WorkerEvent struct {
|
|
Type WorkerEventType `json:"type" avro:"type"`
|
|
Body any `json:"body" avro:"body"`
|
|
}
|
|
|
|
type JobEventType string
|
|
|
|
const (
|
|
JobEventTypeNewEmail JobEventType = "NEW_EMAIL"
|
|
JobEventTypeRemoveEmail JobEventType = "REMOVE_EMAIL"
|
|
JobEventTypeFlagsAdd JobEventType = "FLAGS_ADD"
|
|
JobEventTypeFlagsRemove JobEventType = "FLAGS_REMOVE"
|
|
JobEventTypeEmailUpdate JobEventType = "UPDATE_EMAIL"
|
|
JobEventTypeMailboxUpdate JobEventType = "UPDATE_MAILBOX"
|
|
JobEventTypeMailboxDelete JobEventType = "DELETE_MAILBOX"
|
|
|
|
JobEventTypeTokenUpdate JobEventType = "TOKEN_UPDATE"
|
|
JobEventTypeHistoryIDUpdate JobEventType = "HISTORY_ID_UPDATE"
|
|
|
|
// Task result events from worker
|
|
JobEventTypeEmailSent JobEventType = "EMAIL_SENT"
|
|
JobEventTypeEmailFailed JobEventType = "EMAIL_FAILED"
|
|
|
|
// Error-specific events for worker -> jobsService
|
|
JobEventTypeEmailAuthError JobEventType = "EMAIL_AUTH_ERROR" // Needs re-auth
|
|
JobEventTypeEmailDisabled JobEventType = "EMAIL_DISABLED" // Account disabled
|
|
JobEventTypeEmailRateLimited JobEventType = "EMAIL_RATE_LIMITED" // Rate limit hit
|
|
JobEventTypeEmailServerError JobEventType = "EMAIL_SERVER_ERROR" // Temporary server error
|
|
|
|
// Per-worker health telemetry. Emitted every 30s by every worker;
|
|
// consumer writes it into worker_health_samples for the capacity view.
|
|
JobEventTypeWorkerHealth JobEventType = "WORKER_HEALTH"
|
|
)
|
|
|
|
type JobEvent struct {
|
|
Type JobEventType `json:"type" avro:"type"`
|
|
Body any `json:"body" avro:"body"`
|
|
}
|
|
|
|
// EmailErrorEvent represents an email error event sent from worker to jobsService
|
|
type EmailErrorEvent struct {
|
|
TaskID string `json:"task_id" avro:"task_id"`
|
|
EmailAccountID string `json:"email_account_id" avro:"email_account_id"`
|
|
UserID string `json:"user_id" avro:"user_id"`
|
|
ErrorCode string `json:"error_code" avro:"error_code"`
|
|
ErrorType string `json:"error_type" avro:"error_type"`
|
|
ResolveMethod string `json:"resolve_method" avro:"resolve_method"`
|
|
Message string `json:"message" avro:"message"`
|
|
UserVisible bool `json:"user_visible" avro:"user_visible"`
|
|
UserTitle string `json:"user_title,omitempty" avro:"user_title"`
|
|
UserMessage string `json:"user_message,omitempty" avro:"user_message"`
|
|
ActionRequired string `json:"action_required,omitempty" avro:"action_required"`
|
|
Timestamp int64 `json:"timestamp" avro:"timestamp"`
|
|
}
|