func()

in pkg/api/client/extended/client.go [81:113]


func (c *StepRunnerClient) Follow(ctx context.Context, jobID string, out *FollowOutput) (client.Status, error) {
	if out.Logs == nil {
		return client.Status{}, errors.New("at least one stream sink must be specified")
	}

	ctx, cancel := context.WithCancel(ctx)
	defer cancel()

	eg := errgroup.Group{}

	if out.Logs != nil {
		eg.Go(func() error {
			// TODO: add reconnection
			n, err := c.FollowLogs(ctx, jobID, out.readLogs, out.Logs)
			out.readLogs += n
			if err != nil {
				cancel() // force followSteps to exit
			}
			return err
		})
	}

	var followErr error
	if err := eg.Wait(); err != nil {
		followErr = fmt.Errorf("following job %q: %w", jobID, err)
	}

	status, statErr := c.Status(context.Background(), jobID)
	if statErr != nil {
		return client.Status{}, errors.Join(followErr, statErr)
	}
	return status, followErr
}