| 1 | package console |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "time" |
| 6 | |
| 7 | "github.com/carlosframework/platform/internal/hostclaim" |
| 8 | "github.com/carlosframework/platform/internal/hostops" |
| 9 | ) |
| 10 | |
| 11 | // NewProductionWakeRetryReset selects the bucket protocol. ConfigureClaimRuntime |
| 12 | // supplies the guarded stores and console authority before serving any requests. |
| 13 | func NewProductionWakeRetryReset() *WakeRetryResetDoor { return &WakeRetryResetDoor{production: true} } |
| 14 | |
| 15 | func productionWakeRetryReset(a *hostops.ProductionAuthority) *WakeRetryResetDoor { |
| 16 | transport := hostops.WakeResetTransport{Store: a.Store, Directory: a.Directory, Now: a.Now} |
| 17 | return &WakeRetryResetDoor{production: true, Claims: a.Store, NewID: claimOperationID, |
| 18 | Authority: func(ctx context.Context) error { |
| 19 | return transport.Authority(ctx, a.ConsoleID, a.Enrollment, a.Namespace) |
| 20 | }, |
| 21 | StopAttempt: func(ctx context.Context, o hostclaim.Observed, attempt hostclaim.WakeRetryAttempt) error { |
| 22 | request, err := a.Control.RequestWakeReset(ctx, transport, a.Signer, a.ConsoleID, a.Enrollment, a.Namespace, o, attempt) |
| 23 | if err != nil { |
| 24 | return err |
| 25 | } |
| 26 | err = transport.Wait(ctx, request, 250*time.Millisecond) |
| 27 | if err != nil { |
| 28 | cleanup, done := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second) |
| 29 | defer done() |
| 30 | // This only closes future dispatch. A concurrent root stop may already |
| 31 | // have happened; return the uncertain result and keep the claim intact. |
| 32 | _ = a.Control.CancelWakeReset(cleanup, transport, a.Signer, request) |
| 33 | } |
| 34 | return err |
| 35 | }, |
| 36 | } |
| 37 | } |
| 38 | |