cmd

package
v0.0.227 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package cmd provides the command line interface for the Executor.

Index

Constants

This section is empty.

Variables

View Source
var ExecutorInfoCommand = &cli.Command{
	Name:        "executor-info",
	Description: "learn how to use executor cli",
	Action: func(c *cli.Context) error {
		fmt.Println(string(markdown.Render(help, termsize.Width(), 6)))
		return nil
	},
}

ExecutorInfoCommand gets info about using the executor agent.

View Source
var ExecutorRunCommand = &cli.Command{
	Name:        "executor-run",
	Description: "runs the executor service",
	Flags:       []cli.Flag{configFlag, metricsPortFlag, debugFlag},
	Action: func(c *cli.Context) error {

		var scribeClient client.ScribeClient

		g, ctx := errgroup.WithContext(c.Context)

		handler, err := metrics.NewFromEnv(ctx, metadata.BuildInfo())
		if err != nil {
			return fmt.Errorf("failed to create metrics handler: %w", err)
		}

		executorConfig, executorDB, err := createExecutorParameters(ctx, c, handler)
		if err != nil {
			return err
		}

		switch executorConfig.ScribeConfig.Type {
		case "embedded":
			eventDB, err := scribeAPI.InitDB(
				ctx,
				executorConfig.ScribeConfig.EmbeddedDBConfig.Type,
				executorConfig.ScribeConfig.EmbeddedDBConfig.Source,
				handler,
				false,
			)
			if err != nil {
				return fmt.Errorf("failed to initialize database: %w", err)
			}

			scribeClients := make(map[uint32][]backend.ScribeBackend)

			for _, client := range executorConfig.ScribeConfig.EmbeddedScribeConfig.Chains {
				for confNum := 1; confNum <= scribeCmd.MaxConfirmations; confNum++ {
					backendClient, err := backend.DialBackend(ctx, fmt.Sprintf("%s/%d/rpc/%d", executorConfig.BaseOmnirpcURL, confNum, client.ChainID), handler)
					if err != nil {
						return fmt.Errorf("could not start client for %s", fmt.Sprintf("%s/1/rpc/%d", executorConfig.BaseOmnirpcURL, client.ChainID))
					}

					scribeClients[client.ChainID] = append(scribeClients[client.ChainID], backendClient)
				}
			}

			scribe, err := service.NewScribe(eventDB, scribeClients, executorConfig.ScribeConfig.EmbeddedScribeConfig, handler)
			if err != nil {
				return fmt.Errorf("failed to initialize scribe: %w", err)
			}

			g.Go(func() error {
				err := scribe.Start(ctx)
				if err != nil {
					return fmt.Errorf("failed to start scribe: %w", err)
				}

				return nil
			})

			embedded := client.NewEmbeddedScribe(
				executorConfig.ScribeConfig.EmbeddedDBConfig.Type,
				executorConfig.ScribeConfig.EmbeddedDBConfig.Source,
				handler,
			)

			g.Go(func() error {
				err := embedded.Start(ctx)
				if err != nil {
					return fmt.Errorf("failed to start embedded scribe: %w", err)
				}

				return nil
			})

			scribeClient = embedded.ScribeClient
		case "remote":
			scribeClient = client.NewRemoteScribe(
				uint16(executorConfig.ScribeConfig.Port),
				executorConfig.ScribeConfig.URL,
				handler,
			).ScribeClient
		default:
			return fmt.Errorf("invalid scribe type: %s", executorConfig.ScribeConfig.Type)
		}

		var baseOmniRPCClient omnirpcClient.RPCClient
		if debugFlag.IsSet() {
			baseOmniRPCClient = omnirpcClient.NewOmnirpcClient(executorConfig.BaseOmnirpcURL, handler, omnirpcClient.WithCaptureReqRes())
		} else {
			baseOmniRPCClient = omnirpcClient.NewOmnirpcClient(executorConfig.BaseOmnirpcURL, handler)
		}

		executor, err := executor.NewExecutor(ctx, executorConfig, executorDB, scribeClient, baseOmniRPCClient, handler)
		if err != nil {
			return fmt.Errorf("failed to create executor: %w", err)
		}

		g.Go(func() error {
			err := api.Start(ctx, uint16(c.Uint(metricsPortFlag.Name)))
			if err != nil {
				return fmt.Errorf("failed to start api: %w", err)
			}

			return nil
		})

		g.Go(func() error {
			err := executor.Run(ctx)
			if err != nil {
				return fmt.Errorf("failed to run executor: %w", err)
			}

			return nil
		})

		if err := g.Wait(); err != nil {
			return fmt.Errorf("failed to run executor: %w", err)
		}

		return nil
	},
}

ExecutorRunCommand runs the executor.

Functions

func InitExecutorDB

func InitExecutorDB(parentCtx context.Context, database string, path string, tablePrefix string, handler metrics.Handler) (_ db.ExecutorDB, err error)

InitExecutorDB initializes a database given a database type and path.

func Start

func Start(args []string, buildInfo config.BuildInfo)

Start starts the command line.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL