Run spawns c.numWorkers concurrent poll goroutines and blocks until ctx is canceled. Worker count scales with the number of configured endpoints so that adding more script URLs increases parallelism rather than spreading the same fixed pool thinner.
(ctx context.Context)
| 530 | // adding more script URLs increases parallelism rather than spreading the same |
| 531 | // fixed pool thinner. |
| 532 | func (c *Client) Run(ctx context.Context) error { |
| 533 | var wg sync.WaitGroup |
| 534 | for i := 0; i < c.numWorkers; i++ { |
| 535 | wg.Add(1) |
| 536 | go func() { |
| 537 | defer wg.Done() |
| 538 | c.runWorker(ctx) |
| 539 | }() |
| 540 | } |
| 541 | // Periodic stats line so an operator can spot trends without grepping. |
| 542 | wg.Add(1) |
| 543 | go func() { |
| 544 | defer wg.Done() |
| 545 | c.runStatsLoop(ctx) |
| 546 | }() |
| 547 | // Hourly fetch of each deployment's self-reported invocation count. |
| 548 | // Logged in the next [stats] line as `script=N` next to the existing |
| 549 | // client-side `today=N` so the user sees both perspectives. |
| 550 | wg.Add(1) |
| 551 | go func() { |
| 552 | defer wg.Done() |
| 553 | c.runScriptStatsLoop(ctx) |
| 554 | }() |
| 555 | wg.Add(1) |
| 556 | go func() { |
| 557 | defer wg.Done() |
| 558 | c.runEndpointRecoveryLoop(ctx) |
| 559 | }() |
| 560 | wg.Wait() |
| 561 | return ctx.Err() |
| 562 | } |
| 563 | |
| 564 | func (c *Client) runWorker(ctx context.Context) { |
| 565 | consecutiveIdle := 0 |