Remove run node UI and expire registrations
This commit is contained in:
@@ -73,6 +73,9 @@ func (svc *CoreService) RegisterRunHello(hello domain.RunControlHello) (domain.R
|
||||
svc.controlMu.Lock()
|
||||
defer svc.controlMu.Unlock()
|
||||
|
||||
if err := svc.sweepExpiredRunRegistrationsLocked(stamp); err != nil {
|
||||
return domain.RunControlHelloResult{}, err
|
||||
}
|
||||
if err := svc.upsertRunEndpoint(endpoint); err != nil {
|
||||
return domain.RunControlHelloResult{}, err
|
||||
}
|
||||
@@ -183,6 +186,9 @@ func (svc *CoreService) AcceptRunHeartbeat(heartbeat domain.RunControlHeartbeat)
|
||||
svc.controlMu.Lock()
|
||||
defer svc.controlMu.Unlock()
|
||||
|
||||
if err := svc.sweepExpiredRunRegistrationsLocked(stamp); err != nil {
|
||||
return domain.RunControlHeartbeatResult{}, err
|
||||
}
|
||||
session, err := svc.currentRunSession(heartbeat.RunEndpointID, heartbeat.SessionToken)
|
||||
if err != nil {
|
||||
return domain.RunControlHeartbeatResult{}, err
|
||||
@@ -230,6 +236,43 @@ func (svc *CoreService) upsertRunEndpoint(endpoint domain.RunEndpoint) error {
|
||||
return svc.store.RunEndpoints().Update(endpoint)
|
||||
}
|
||||
|
||||
func (svc *CoreService) sweepExpiredRunRegistrationsLocked(stamp time.Time) error {
|
||||
endpoints, err := svc.store.RunEndpoints().List(domain.RunEndpointFilter{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, endpoint := range endpoints {
|
||||
if runEndpointRegistrationCurrentAt(endpoint, stamp) {
|
||||
continue
|
||||
}
|
||||
if err := svc.store.RunEndpoints().Delete(endpoint.ID); err != nil && !errors.Is(err, repo.ErrNotFound) {
|
||||
return err
|
||||
}
|
||||
delete(svc.runSessions, endpoint.ID)
|
||||
session, err := svc.store.RunControlSessions().Get(endpoint.ID)
|
||||
if err != nil {
|
||||
if errors.Is(err, repo.ErrNotFound) {
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
if session.Status != domain.AuthSessionStatusActive {
|
||||
continue
|
||||
}
|
||||
session.Status = domain.AuthSessionStatusRevoked
|
||||
session.RevokedAt = stamp
|
||||
session.UpdatedAt = stamp
|
||||
if err := svc.store.RunControlSessions().Update(session); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func runEndpointRegistrationCurrentAt(endpoint domain.RunEndpoint, stamp time.Time) bool {
|
||||
return !endpoint.LastHeartbeatAt.IsZero() && !stamp.After(endpoint.LastHeartbeatAt.Add(runHeartbeatStaleAfter))
|
||||
}
|
||||
|
||||
func (svc *CoreService) nextSessionToken() (string, error) {
|
||||
return randomToken()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user