Download this file
| 1 | package host |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "time" |
| 6 | |
| 7 | "github.com/carlosframework/platform/internal/activator" |
| 8 | ) |
| 9 | |
| 10 | func joinAgentShutdown(seedCtx context.Context, seedCancel context.CancelFunc, seedServer *filesSeedServer, cancelStartup context.CancelFunc, startupDone, dutiesDone <-chan struct{}) (context.Context, context.CancelFunc, error) { |
| 11 | base := context.Background() |
| 12 | cancel := func() {} |
| 13 | if seedCtx != nil { |
| 14 | base, cancel = activator.CleanupContext(base, 60*time.Second) |
| 15 | } |
| 16 | cancelStartup() |
| 17 | if seedCtx != nil { |
| 18 | seedCancel() |
| 19 | join, stop := activator.CleanupContext(seedCtx, 30*time.Second) |
| 20 | err := seedServer.close(join) |
| 21 | stop() |
| 22 | if err != nil { |
| 23 | return base, cancel, err |
| 24 | } |
| 25 | } |
| 26 | join, stop := context.WithTimeout(base, 5*time.Second) |
| 27 | defer stop() |
| 28 | joinAgentStartup(join, startupDone) |
| 29 | joinAgentStartup(join, dutiesDone) |
| 30 | if seedCtx == nil { |
| 31 | // Main starts this clock after joining startup duties. |
| 32 | base, cancel = context.WithTimeout(context.Background(), 60*time.Second) |
| 33 | } |
| 34 | return base, cancel, nil |
| 35 | } |
| 36 | |