fix: 从后端恢复 Runner claim
This commit is contained in:
@@ -108,6 +108,30 @@ type Backend struct {
|
||||
Config Config
|
||||
}
|
||||
|
||||
func (b Backend) RecoverAssignments(ctx context.Context, trustDomain string) ([]taskassignment.Assignment, error) {
|
||||
if err := b.validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result, err := b.Lifecycle.ListSandboxes(ctx, opensandbox.ListOptions{
|
||||
Metadata: map[string]string{"ci.ddupan.top/backend": "vm"}, PageSize: 100,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list recoverable sandboxes: %w", err)
|
||||
}
|
||||
assignments := make([]taskassignment.Assignment, 0, len(result.Items))
|
||||
for _, sandbox := range result.Items {
|
||||
if sandbox.Metadata[terminalMetadata] == "true" {
|
||||
continue
|
||||
}
|
||||
assignment, err := taskassignment.FromMetadata(sandbox.Metadata, sandbox.Metadata, trustDomain)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("recover sandbox %s: %w", sandbox.ID, err)
|
||||
}
|
||||
assignments = append(assignments, assignment)
|
||||
}
|
||||
return assignments, nil
|
||||
}
|
||||
|
||||
func NewLifecycleClient(baseURL, apiKey string, client *http.Client) *opensandbox.LifecycleClient {
|
||||
if client != nil {
|
||||
return opensandbox.NewLifecycleClient(baseURL, apiKey, opensandbox.WithHTTPClient(client))
|
||||
|
||||
Reference in New Issue
Block a user