Documentation
¶
Index ¶
- Variables
- func AssignQuorumHead(quorumID int64) (string, error)
- func GetQuorum() (int64, error)
- type CacheData
- type CacheManager
- type Job
- type JobScheduler
- type LoadBalancer
- func (lb *LoadBalancer) AddToWaitingQueue(job *Job, estimatedTime time.Time)
- func (lb *LoadBalancer) CalculateEstimatedWaitTime(jobs map[string]*Job) time.Time
- func (lb *LoadBalancer) CheckResourceAvailability() bool
- func (lb *LoadBalancer) GetNextWaitingJob() (*WaitingJob, bool)
- func (lb *LoadBalancer) GetQueueStatus() int
- func (lb *LoadBalancer) GetSystemMetrics() SystemResources
- func (lb *LoadBalancer) MonitorResources()
- func (lb *LoadBalancer) SetResourceLimits(cpuThreshold, memoryThreshold float64)
- type Quorum
- type QuorumData
- type QuorumResponse
- type SystemResources
- type WaitingJob
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidTimeframe = fmt.Errorf("invalid timeframe specified")
)
Functions ¶
func AssignQuorumHead ¶
Types ¶
type CacheData ¶
type CacheData struct { Jobs map[string]*Job `json:"jobs"` Quorums map[string]*Quorum `json:"quorums"` WaitingQueue []WaitingJob `json:"waiting_queue"` LastUpdated time.Time `json:"last_updated"` SystemResources SystemResources `json:"system_resources"` }
CacheData represents the scheduler state that needs to be persisted
type CacheManager ¶
type CacheManager struct {
// contains filtered or unexported fields
}
CacheManager handles persistence of scheduler state
func NewCacheManager ¶
func NewCacheManager(scheduler *JobScheduler, cacheInterval time.Duration) (*CacheManager, error)
NewCacheManager creates a new cache manager instance
func (*CacheManager) LoadState ¶
func (cm *CacheManager) LoadState() error
LoadState restores scheduler state from cache
func (*CacheManager) SaveState ¶
func (cm *CacheManager) SaveState() error
SaveState persists the current scheduler state to disk
func (*CacheManager) Start ¶
func (cm *CacheManager) Start()
Start begins periodic caching of scheduler state
type Job ¶
type Job struct { JobID string ArgType string Arguments map[string]interface{} ChainID string ContractAddress string JobCostPrediction float64 Stake float64 Status string TargetFunction string TimeFrame int64 // in seconds TimeInterval int64 // in seconds UserID string CreatedAt time.Time MaxRetries int CurrentRetries int LastExecuted time.Time NextExecutionTime time.Time Error string Payload map[string]interface{} CodeURL string }
Job represents a scheduled task with its properties
type JobScheduler ¶
type JobScheduler struct { Cron *cron.Cron // contains filtered or unexported fields }
JobScheduler enhanced with load balancing
func NewJobScheduler ¶
func NewJobScheduler(workersCount int, dbClient *database.Connection) *JobScheduler
NewJobScheduler creates an enhanced scheduler with resource limits
func (*JobScheduler) AddJob ¶
func (js *JobScheduler) AddJob(jobID string) error
AddJob enhanced with resource checking
func (*JobScheduler) GetQueueStatus ¶
func (js *JobScheduler) GetQueueStatus() map[string]interface{}
GetQueueStatus returns the current status of job queues
func (*JobScheduler) GetSystemMetrics ¶
func (js *JobScheduler) GetSystemMetrics() SystemResources
GetSystemMetrics returns current system metrics
func (*JobScheduler) UpdateJob ¶
func (js *JobScheduler) UpdateJob(jobID int64)
UpdateJob updates the status of a job in the scheduler
type LoadBalancer ¶
type LoadBalancer struct {
// contains filtered or unexported fields
}
LoadBalancer handles system resources and job queuing
func NewLoadBalancer ¶
func NewLoadBalancer() *LoadBalancer
NewLoadBalancer creates a new load balancer instance
func (*LoadBalancer) AddToWaitingQueue ¶
func (lb *LoadBalancer) AddToWaitingQueue(job *Job, estimatedTime time.Time)
AddToWaitingQueue adds a job to the waiting queue
func (*LoadBalancer) CalculateEstimatedWaitTime ¶
func (lb *LoadBalancer) CalculateEstimatedWaitTime(jobs map[string]*Job) time.Time
CalculateEstimatedWaitTime estimates when resources might be available
func (*LoadBalancer) CheckResourceAvailability ¶
func (lb *LoadBalancer) CheckResourceAvailability() bool
CheckResourceAvailability verifies if system can handle new jobs
func (*LoadBalancer) GetNextWaitingJob ¶
func (lb *LoadBalancer) GetNextWaitingJob() (*WaitingJob, bool)
GetNextWaitingJob returns and removes the next job from the waiting queue
func (*LoadBalancer) GetQueueStatus ¶
func (lb *LoadBalancer) GetQueueStatus() int
GetQueueStatus returns the current status of waiting queue
func (*LoadBalancer) GetSystemMetrics ¶
func (lb *LoadBalancer) GetSystemMetrics() SystemResources
GetSystemMetrics returns current system metrics
func (*LoadBalancer) MonitorResources ¶
func (lb *LoadBalancer) MonitorResources()
MonitorResources continuously monitors system resources
func (*LoadBalancer) SetResourceLimits ¶
func (lb *LoadBalancer) SetResourceLimits(cpuThreshold, memoryThreshold float64)
SetResourceLimits updates the resource thresholds
type Quorum ¶
type Quorum struct { QuorumID string NodeCount int ActiveNodes []string Status string ChainID string CreatedAt time.Time UpdatedAt time.Time }
Quorum represents a group of nodes that can execute jobs
type QuorumData ¶
type QuorumResponse ¶
type QuorumResponse struct {
FreeQuorumIDs []int64 `json:"free_quorum_ids"`
}
type SystemResources ¶
type SystemResources struct { CPUUsage float64 MemoryUsage float64 MaxCPU float64 MaxMemory float64 }
SystemResources tracks system resource usage
type WaitingJob ¶
WaitingJob represents a job waiting in queue