MCPcopy
hub / github.com/cortexlabs/cortex / try

Method try

pkg/activator/api_activator.go:47–72  ·  view source on GitHub ↗

try waits for the readinessTracker to be ready and then attempts to execute the passed callback. If the readinessTracker does not reach a ready state, it will timeout.

(ctx context.Context, fn func() error, tracker *readinessTracker)

Source from the content-addressed store, hash-verified

45// try waits for the readinessTracker to be ready and then attempts to execute the passed callback.
46// If the readinessTracker does not reach a ready state, it will timeout.
47func (a *apiActivator) try(ctx context.Context, fn func() error, tracker *readinessTracker) error {
48 var execErr error
49
50 if err := a.breaker.Maybe(ctx, func() {
51 ctx, cancel := context.WithTimeout(ctx, consts.WaitForReadyReplicasTimeout)
52 defer cancel()
53
54 if !tracker.IsReady() {
55 loop:
56 for {
57 select {
58 case <-ctx.Done():
59 execErr = errors.Wrap(ctx.Err(), "no ready replicas available")
60 return
61 case <-tracker.Wait():
62 break loop
63 }
64 }
65 }
66 execErr = fn()
67 }); err != nil {
68 return err
69 }
70
71 return execErr
72}
73
74// updateQueueParams updates the breaker queue parameters (not thread safe)
75func (a *apiActivator) updateQueueParams(maxQueueLength, maxConcurrency int) {

Callers 2

TestApiActivator_TryFunction · 0.80
TryMethod · 0.80

Calls 4

WrapFunction · 0.92
MaybeMethod · 0.80
IsReadyMethod · 0.80
WaitMethod · 0.80

Tested by 1

TestApiActivator_TryFunction · 0.64