type Worker struct { cfg WorkerConfig masterConn *grpc.ClientConn masterCli proto.JobQueueClient } // NewWorker creates a new Worker instance with the specified configuration. func NewWorker(cfg WorkerConfig) (*Worker, error) { if err := cfg.Validate(); err != nil { return nil, xerrors.Errorf("worker config validation failed: %w", err) } return &Worker{cfg: cfg}, nil } // Dial establishes a connection to the master node. func (w *Worker) Dial(masterEndpoint string, dialTimeout time.Duration) error { var dialCtx context.Context if dialTimeout != 0 { var cancelFn func() dialCtx, cancelFn = context.WithTimeout(context.Background(), dialTimeout) defer cancelFn() } conn, err := grpc.DialContext(dialCtx, masterEndpoint, grpc.WithInsecure(), grpc.WithBlock()) if err != nil { return xerrors.Errorf("unable to dial master: %w", err) } w.masterConn = conn w.masterCli = proto.NewJobQueueClient(conn) return nil }