fix local run startup and stale dispatch
This commit is contained in:
@@ -1509,6 +1509,9 @@ func (svc *CoreService) CreateRunEndpoint(endpoint domain.RunEndpoint) (domain.R
|
||||
if endpoint.Status == "" {
|
||||
endpoint.Status = domain.RunEndpointStatusOnline
|
||||
}
|
||||
if endpoint.LastHeartbeatAt.IsZero() && (endpoint.Status == domain.RunEndpointStatusOnline || endpoint.Status == domain.RunEndpointStatusDegraded) {
|
||||
endpoint.LastHeartbeatAt = svc.now()
|
||||
}
|
||||
if err := validator.ValidateRunEndpoint(endpoint); err != nil {
|
||||
return domain.RunEndpoint{}, err
|
||||
}
|
||||
@@ -2158,7 +2161,7 @@ func (svc *CoreService) CreateJob(job domain.Job) (domain.Job, error) {
|
||||
if err != nil {
|
||||
return domain.Job{}, fmt.Errorf("get run endpoint dependency: %w", err)
|
||||
}
|
||||
if err := validateRunnableEndpoint(endpoint, job.Capability); err != nil {
|
||||
if err := svc.validateRunnableEndpoint(endpoint, job.Capability); err != nil {
|
||||
return domain.Job{}, err
|
||||
}
|
||||
if job.ServerInstanceID != "" {
|
||||
@@ -2281,16 +2284,26 @@ func (svc *CoreService) ListAuditEvents(filter domain.AuditEventFilter) ([]domai
|
||||
return svc.store.AuditEvents().List(filter)
|
||||
}
|
||||
|
||||
func validateRunnableEndpoint(endpoint domain.RunEndpoint, capability string) error {
|
||||
func (svc *CoreService) validateRunnableEndpoint(endpoint domain.RunEndpoint, capability string) error {
|
||||
if endpoint.Status != domain.RunEndpointStatusOnline && endpoint.Status != domain.RunEndpointStatusDegraded {
|
||||
return validationError("run endpoint must be online or degraded")
|
||||
}
|
||||
if !svc.runEndpointHeartbeatCurrent(endpoint) {
|
||||
return validationError("run endpoint heartbeat is stale")
|
||||
}
|
||||
if len(validator.MissingCapabilities(endpoint.Capabilities, []string{capability})) > 0 {
|
||||
return validationError("run endpoint missing required capability: " + capability)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (svc *CoreService) runEndpointHeartbeatCurrent(endpoint domain.RunEndpoint) bool {
|
||||
if endpoint.LastHeartbeatAt.IsZero() {
|
||||
return false
|
||||
}
|
||||
return !svc.now().After(endpoint.LastHeartbeatAt.Add(capacityHeartbeatStaleAfter))
|
||||
}
|
||||
|
||||
func validateJobServerTarget(job domain.Job, instance domain.ServerInstance, plugin domain.GamePlugin) error {
|
||||
if instance.State == domain.ServerInstanceStateDeleted {
|
||||
return validationError("server instance must not be deleted")
|
||||
|
||||
Reference in New Issue
Block a user