gitlab.com/SkynetLabs/skyd@v1.6.9/skymodules/renter/workerstatus.go (about) 1 package renter 2 3 import ( 4 "time" 5 6 "gitlab.com/SkynetLabs/skyd/skymodules" 7 ) 8 9 // callStatus returns the status of the worker. 10 func (w *worker) callStatus() skymodules.WorkerStatus { 11 // Fetch cool down info on all queues of interest 12 downloadOnCD, downloadTerminated, downloadQueueSize, downloadCDTime, downloadCDErr := w.staticJobReadQueue.callCooldownStatus() 13 hasSectorOnCD, hasSectorTerminated, hasSectorQueueSize, hasSectorCDTime, hasSectorCDErr := w.staticJobHasSectorQueue.callCooldownStatus() 14 lowPrioOnCD, lowPrioTerminated, lowPrioQueueSize, lowPrioCDTime, lowPrioCDErr := w.staticJobLowPrioReadQueue.callCooldownStatus() 15 16 w.mu.Lock() 17 defer w.mu.Unlock() 18 19 uploadOnCoolDown, uploadCoolDownTime := w.onUploadCooldown() 20 var uploadCoolDownErr string 21 if w.uploadRecentFailureErr != nil { 22 uploadCoolDownErr = w.uploadRecentFailureErr.Error() 23 } 24 25 maintenanceOnCooldown, maintenanceCoolDownTime, maintenanceCoolDownErr := w.staticMaintenanceState.managedMaintenanceCooldownStatus() 26 var maintenanceCoolDownErrStr string 27 if maintenanceCoolDownErr != nil { 28 maintenanceCoolDownErrStr = maintenanceCoolDownErr.Error() 29 } 30 31 // Update the worker cache before returning a status. 32 w.staticTryUpdateCache() 33 cache := w.staticCache() 34 return skymodules.WorkerStatus{ 35 // Contract Information 36 ContractID: cache.staticContractID, 37 ContractUtility: cache.staticContractUtility, 38 HostPubKey: w.staticHostPubKey, 39 40 // Download information 41 DownloadCoolDownError: downloadCDErr, 42 DownloadCoolDownTime: downloadCDTime, 43 DownloadOnCoolDown: downloadOnCD, 44 DownloadQueueSize: downloadQueueSize, 45 DownloadTerminated: downloadTerminated, 46 47 // Has Sector information 48 HasSectorCoolDownError: hasSectorCDErr, 49 HasSectorCoolDownTime: hasSectorCDTime, 50 HasSectorOnCoolDown: hasSectorOnCD, 51 HasSectorQueueSize: hasSectorQueueSize, 52 HasSectorTerminated: hasSectorTerminated, 53 54 // Low Prio Download (repairs) information 55 LowPrioDownloadCoolDownError: lowPrioCDErr, 56 LowPrioDownloadCoolDownTime: lowPrioCDTime, 57 LowPrioDownloadOnCoolDown: lowPrioOnCD, 58 LowPrioDownloadQueueSize: lowPrioQueueSize, 59 LowPrioDownloadTerminated: lowPrioTerminated, 60 61 // Upload information 62 UploadCoolDownError: uploadCoolDownErr, 63 UploadCoolDownTime: uploadCoolDownTime, 64 UploadOnCoolDown: uploadOnCoolDown, 65 UploadQueueSize: w.unprocessedChunks.Len(), 66 UploadTerminated: w.uploadTerminated, 67 68 // Job Queues 69 DownloadSnapshotJobQueueSize: int(w.staticJobDownloadSnapshotQueue.callStatus().size), 70 UploadSnapshotJobQueueSize: int(w.staticJobUploadSnapshotQueue.callStatus().size), 71 72 // Maintenance Cooldown Information 73 MaintenanceOnCooldown: maintenanceOnCooldown, 74 MaintenanceCoolDownError: maintenanceCoolDownErrStr, 75 MaintenanceCoolDownTime: maintenanceCoolDownTime, 76 77 // Account Information 78 AccountBalanceTarget: w.staticRenter.staticAccountBalanceTarget, 79 AccountStatus: w.staticAccount.managedStatus(), 80 81 // Price Table Information 82 PriceTableStatus: w.staticPriceTableStatus(), 83 84 // Read Job Information 85 ReadJobsStatus: w.callReadJobStatus(), 86 87 // HasSector Job Information 88 HasSectorJobsStatus: w.callHasSectorJobStatus(), 89 90 // ReadRegistry Job Information 91 ReadRegistryJobsStatus: w.callReadRegistryJobsStatus(), 92 93 // UpdateRegistry Job Information 94 UpdateRegistryJobsStatus: w.callUpdateRegistryJobsStatus(), 95 } 96 } 97 98 // staticPriceTableStatus returns the status of the worker's price table 99 func (w *worker) staticPriceTableStatus() skymodules.WorkerPriceTableStatus { 100 pt := w.staticPriceTable() 101 102 var recentErrStr string 103 if pt.staticRecentErr != nil { 104 recentErrStr = pt.staticRecentErr.Error() 105 } 106 107 return skymodules.WorkerPriceTableStatus{ 108 ExpiryTime: pt.staticExpiryTime, 109 UpdateTime: pt.staticUpdateTime, 110 111 Active: time.Now().Before(pt.staticExpiryTime), 112 113 RecentErr: recentErrStr, 114 RecentErrTime: pt.staticRecentErrTime, 115 } 116 } 117 118 // callReadJobStatus returns the status of the read job queue 119 func (w *worker) callReadJobStatus() skymodules.WorkerReadJobsStatus { 120 jrq := w.staticJobReadQueue 121 status := jrq.callStatus() 122 123 var recentErrString string 124 if status.recentErr != nil { 125 recentErrString = status.recentErr.Error() 126 } 127 128 avgJobTimeInMs := func(l uint64) uint64 { 129 if d := jrq.staticStats.callExpectedJobTime(l); d > 0 { 130 return uint64(d.Milliseconds()) 131 } 132 return 0 133 } 134 135 return skymodules.WorkerReadJobsStatus{ 136 AvgJobTime64k: avgJobTimeInMs(1 << 16), 137 AvgJobTime1m: avgJobTimeInMs(1 << 20), 138 AvgJobTime4m: avgJobTimeInMs(1 << 22), 139 ConsecutiveFailures: status.consecutiveFailures, 140 JobQueueSize: status.size, 141 RecentErr: recentErrString, 142 RecentErrTime: status.recentErrTime, 143 } 144 } 145 146 // callHasSectorJobStatus returns the status of the has sector job queue 147 func (w *worker) callHasSectorJobStatus() skymodules.WorkerHasSectorJobsStatus { 148 hsq := w.staticJobHasSectorQueue 149 status := hsq.callStatus() 150 151 var recentErrStr string 152 if status.recentErr != nil { 153 recentErrStr = status.recentErr.Error() 154 } 155 156 avgJobTimeInMs := uint64(hsq.callExpectedJobTime().Milliseconds()) 157 158 return skymodules.WorkerHasSectorJobsStatus{ 159 AvgJobTime: avgJobTimeInMs, 160 ConsecutiveFailures: status.consecutiveFailures, 161 JobQueueSize: status.size, 162 RecentErr: recentErrStr, 163 RecentErrTime: status.recentErrTime, 164 } 165 } 166 167 // callGenericWorkerJobStatus returns the status for the generic job queue. 168 func callGenericWorkerJobStatus(queue *jobGenericQueue) skymodules.WorkerGenericJobsStatus { 169 status := queue.callStatus() 170 171 var recentErrStr string 172 if status.recentErr != nil { 173 recentErrStr = status.recentErr.Error() 174 } 175 176 return skymodules.WorkerGenericJobsStatus{ 177 ConsecutiveFailures: status.consecutiveFailures, 178 JobQueueSize: status.size, 179 OnCooldown: time.Now().Before(status.cooldownUntil), 180 OnCooldownUntil: status.cooldownUntil, 181 RecentErr: recentErrStr, 182 RecentErrTime: status.recentErrTime, 183 } 184 } 185 186 // callUpdateRegistryJobsStatus returns the status for the ReadRegistry queue. 187 func (w *worker) callReadRegistryJobsStatus() skymodules.WorkerReadRegistryJobStatus { 188 return skymodules.WorkerReadRegistryJobStatus{ 189 WorkerGenericJobsStatus: callGenericWorkerJobStatus(w.staticJobReadRegistryQueue.jobGenericQueue), 190 } 191 } 192 193 // callUpdateRegistryJobsStatus returns the status for the UpdateRegistry queue. 194 func (w *worker) callUpdateRegistryJobsStatus() skymodules.WorkerUpdateRegistryJobStatus { 195 return skymodules.WorkerUpdateRegistryJobStatus{ 196 WorkerGenericJobsStatus: callGenericWorkerJobStatus(w.staticJobUpdateRegistryQueue.jobGenericQueue), 197 } 198 }