command

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCommandNotFound                    = xerror.NotFound(nil, "command.notFound", "command not found")
	ErrNoNextExecutableCommand            = xerror.NotFound(nil, "command.noNextExecutable", "no next executable command")
	ErrNoCommandBeingProcessed            = xerror.BadRequest(nil, "command.noCommandBeingProcessed", "no command being processed")
	ErrCommandInProcessingCanNotBeDeleted = xerror.BadRequest(nil, "command.inProcessingCanNotBeDeleted", "command in processing can not be deleted")
	ErrCommandAlreadyExists               = xerror.Conflict(nil, "command.alreadyExists", "command already exists")

	ErrRunningCommandNotFound = xerror.NotFound(nil, "command.runningCommandNotFound", "running command not found")
	ErrRunningCommandExists   = xerror.BadRequest(nil, "command.runningCommandExists", "running command already exists")
)

Functions

This section is empty.

Types

type CancelableCommand added in v0.15.0

type CancelableCommand struct {
	Command
	// contains filtered or unexported fields
}

CancelableCommand is a command that can be canceled.

func NewCancelableCommand added in v0.15.0

func NewCancelableCommand(ctx context.Context, cmd Command) CancelableCommand

func (*CancelableCommand) CanBeCanceled added in v0.16.0

func (c *CancelableCommand) CanBeCanceled() bool

func (*CancelableCommand) Cancel added in v0.15.0

func (c *CancelableCommand) Cancel()

func (*CancelableCommand) Context added in v0.15.0

func (c *CancelableCommand) Context() context.Context

type CargoCheckQRInputs

type CargoCheckQRInputs struct {
	QRCode string `json:"qr_code" validate:"required"`
}

func (CargoCheckQRInputs) CommandType

func (CargoCheckQRInputs) CommandType() CommandType

type CargoCheckQROutputs

type CargoCheckQROutputs struct{}

func (CargoCheckQROutputs) CommandType

func (CargoCheckQROutputs) CommandType() CommandType

type CargoCloseInputs

type CargoCloseInputs struct {
	MotorSpeed uint8 `json:"motor_speed" validate:"required,max=100"`
}

func (CargoCloseInputs) CommandType

func (CargoCloseInputs) CommandType() CommandType

type CargoCloseOutputs

type CargoCloseOutputs struct{}

func (CargoCloseOutputs) CommandType

func (CargoCloseOutputs) CommandType() CommandType

type CargoLiftInputs

type CargoLiftInputs struct {
	Position   uint16 `json:"position" validate:"required"`
	MotorSpeed uint8  `json:"motor_speed" validate:"required,max=100"`
}

func (CargoLiftInputs) CommandType

func (CargoLiftInputs) CommandType() CommandType

type CargoLiftOutputs

type CargoLiftOutputs struct{}

func (CargoLiftOutputs) CommandType

func (CargoLiftOutputs) CommandType() CommandType

type CargoLowerInputs

type CargoLowerInputs struct {
	Position   uint16 `json:"position" validate:"required"`
	MotorSpeed uint8  `json:"motor_speed" validate:"required,max=100"`
}

func (CargoLowerInputs) CommandType

func (CargoLowerInputs) CommandType() CommandType

type CargoLowerOutputs

type CargoLowerOutputs struct{}

func (CargoLowerOutputs) CommandType

func (CargoLowerOutputs) CommandType() CommandType

type CargoOpenInputs

type CargoOpenInputs struct {
	MotorSpeed uint8 `json:"motor_speed" validate:"required,max=100"`
}

func (CargoOpenInputs) CommandType

func (CargoOpenInputs) CommandType() CommandType

type CargoOpenOutputs

type CargoOpenOutputs struct{}

func (CargoOpenOutputs) CommandType

func (CargoOpenOutputs) CommandType() CommandType

type Command

type Command struct {
	ID          int64
	Type        CommandType
	Status      Status
	Source      Source
	Inputs      Inputs
	Outputs     Outputs
	Error       *string
	StartedAt   *time.Time
	CompletedAt *time.Time
	CreatedAt   time.Time
	UpdatedAt   time.Time
	RequestID   *string
}

func NewCommand

func NewCommand(source Source, inputs Inputs, requestID *string) Command

type CommandType

type CommandType string
const (
	CommandTypeStopMovement CommandType = "STOP_MOVEMENT"
	CommandTypeMoveForward  CommandType = "MOVE_FORWARD"
	CommandTypeMoveBackward CommandType = "MOVE_BACKWARD"
	CommandTypeMoveTo       CommandType = "MOVE_TO"

	CommandTypeCargoOpen    CommandType = "CARGO_OPEN"
	CommandTypeCargoClose   CommandType = "CARGO_CLOSE"
	CommandTypeCargoLift    CommandType = "CARGO_LIFT"
	CommandTypeCargoLower   CommandType = "CARGO_LOWER"
	CommandTypeCargoCheckQR CommandType = "CARGO_CHECK_QR"

	CommandTypeScanLocation CommandType = "SCAN_LOCATION"
	CommandTypeWait         CommandType = "WAIT"
)

func (CommandType) String

func (c CommandType) String() string

func (CommandType) Validate

func (c CommandType) Validate() error

type CreateCommandParams

type CreateCommandParams struct {
	Source    Source  `validate:"enum"`
	Inputs    Inputs  `validate:"required"`
	RequestID *string `validate:"omitempty,max=64"` // Optional request ID for idempotency
}

type DeleteCommandByIDParams

type DeleteCommandByIDParams struct {
	CommandID int64 `validate:"required,min=1"`
}

type ExecutorService added in v0.15.0

type ExecutorService interface {
	Execute(ctx context.Context, cmd Command) error
}

type GetCommandByIDParams

type GetCommandByIDParams struct {
	CommandID int64 `validate:"required,min=1"`
}

type Inputs

type Inputs interface {
	CommandType() CommandType
	// contains filtered or unexported methods
}

func UnmarshalInputs

func UnmarshalInputs(cmdType CommandType, inputsBytes []byte) (Inputs, error)

type ListCommandsParams

type ListCommandsParams struct {
	PagingParams paging.Params `validate:"required"`
	Sorts        []sort.Sort   `validate:"sort=type status source created_at updated_at completed_at"`
	Statuses     []Status      `validate:"dive,enum"`
}

type Location

type Location struct {
	Location  string    `json:"location"`
	ScannedAt time.Time `json:"scanned_at"`
}

type MoveBackwardInputs

type MoveBackwardInputs struct {
	MotorSpeed uint8 `json:"motor_speed" validate:"required,max=100"`
}

func (MoveBackwardInputs) CommandType

func (MoveBackwardInputs) CommandType() CommandType

type MoveBackwardOutputs

type MoveBackwardOutputs struct{}

func (MoveBackwardOutputs) CommandType

func (MoveBackwardOutputs) CommandType() CommandType

type MoveDirection added in v0.13.0

type MoveDirection string
const (
	MoveDirectionForward  MoveDirection = "FORWARD"
	MoveDirectionBackward MoveDirection = "BACKWARD"
)

func (MoveDirection) String added in v0.13.0

func (m MoveDirection) String() string

func (MoveDirection) Validate added in v0.13.0

func (m MoveDirection) Validate() error

type MoveForwardInputs

type MoveForwardInputs struct {
	MotorSpeed uint8 `json:"motor_speed" validate:"required,max=100"`
}

func (MoveForwardInputs) CommandType

func (MoveForwardInputs) CommandType() CommandType

type MoveForwardOutputs

type MoveForwardOutputs struct{}

func (MoveForwardOutputs) CommandType

func (MoveForwardOutputs) CommandType() CommandType

type MoveToInputs

type MoveToInputs struct {
	Location   string        `json:"location" validate:"required"`
	Direction  MoveDirection `json:"direction" validate:"required,enum"`
	MotorSpeed uint8         `json:"motor_speed" validate:"required,max=100"`
}

func (MoveToInputs) CommandType

func (MoveToInputs) CommandType() CommandType

type MoveToOutputs

type MoveToOutputs struct{}

func (MoveToOutputs) CommandType

func (MoveToOutputs) CommandType() CommandType

type Outputs

type Outputs interface {
	CommandType() CommandType
	// contains filtered or unexported methods
}

func UnmarshalOutputs

func UnmarshalOutputs(cmdType CommandType, outputsBytes []byte) (Outputs, error)

type ProcessingLock added in v0.13.0

type ProcessingLock interface {
	// WithLock acquires the lock and executes the function.
	// The lock is released when the function returns.
	WithLock(fn func() error) error

	// WaitUntilUnlocked blocks the execution until the lock is released.
	// If the context is canceled, the function returns immediately.
	WaitUntilUnlocked(ctx context.Context) error
}

ProcessingLock is responsible for controlling a lock mechanism that prevents the system from automatically picking up and processing the next command in the queue.

Note: This lock does not handle stopping or canceling a command that is already being executed. Its sole purpose is to block the transition to the next command, ensuring that no new command is started while the lock is held.

type Repository

type Repository interface {
	ListCommands(ctx context.Context, params ListCommandsParams) (paging.List[Command], error)
	GetNextExecutableCommand(ctx context.Context) (Command, error)
	GetCurrentProcessingCommand(ctx context.Context) (Command, error)
	GetCommandByID(ctx context.Context, id int64) (Command, error)
	CreateCommand(ctx context.Context, command Command) (Command, error)
	UpdateCommand(ctx context.Context, params UpdateCommandParams) (Command, error)

	// CancelPendingCommands cancels all pending commands by status QUEUED, PROCESSING, and CANCELING.
	CancelPendingCommands(ctx context.Context) error
	CancelQueuedAndProcessingCommandsCreatedByCloud(ctx context.Context) error

	// DeleteCommandByID deletes a command by id.
	// It does not delete the command if the status is PROCESSING, CANCELING.
	DeleteCommandByID(ctx context.Context, id int64) error
	DeleteOldCommands(ctx context.Context, cutoffTime time.Time) error
}

type RunningCommandRepository added in v0.15.0

type RunningCommandRepository interface {
	Get(ctx context.Context) (CancelableCommand, error)
	Add(ctx context.Context, cmd CancelableCommand) error
	Update(ctx context.Context, cmd CancelableCommand) error
	Remove(ctx context.Context) error
}

type ScanLocationInputs

type ScanLocationInputs struct{}

func (ScanLocationInputs) CommandType

func (ScanLocationInputs) CommandType() CommandType

type ScanLocationOutputs

type ScanLocationOutputs struct {
	Locations []Location `json:"locations"`
}

func (ScanLocationOutputs) CommandType

func (ScanLocationOutputs) CommandType() CommandType

type Service

type Service interface {
	GetCommandByID(ctx context.Context, params GetCommandByIDParams) (Command, error)
	GetCurrentProcessingCommand(ctx context.Context) (Command, error)
	ListCommands(ctx context.Context, params ListCommandsParams) (paging.List[Command], error)
	CreateCommand(ctx context.Context, params CreateCommandParams) (Command, error)
	CancelCurrentProcessingCommand(ctx context.Context) error

	// CancelActiveCloudCommands cancels all QUEUED and PROCESSING commands created by the cloud.
	CancelActiveCloudCommands(ctx context.Context) error

	RunNextExecutableCommand(ctx context.Context) error

	// CancelAllRunningCommands cancels all running commands including the current processing command
	// and the commands in the queue.
	CancelAllRunningCommands(ctx context.Context) error

	DeleteCommandByID(ctx context.Context, params DeleteCommandByIDParams) error
	DeleteOldCommands(ctx context.Context) error
}

type Source

type Source string
const (
	SourceApp   Source = "APP"
	SourceCloud Source = "CLOUD"
)

func (Source) String

func (s Source) String() string

func (Source) Validate

func (s Source) Validate() error

type Status

type Status string
const (
	StatusQueued     Status = "QUEUED"
	StatusProcessing Status = "PROCESSING"
	StatusCanceling  Status = "CANCELING"
	StatusSucceeded  Status = "SUCCEEDED"
	StatusFailed     Status = "FAILED"
	StatusCanceled   Status = "CANCELED"
)

func (Status) String

func (s Status) String() string

func (Status) Validate

func (s Status) Validate() error

type StopMovementInputs

type StopMovementInputs struct{}

func (StopMovementInputs) CommandType

func (StopMovementInputs) CommandType() CommandType

type StopMovementOutputs

type StopMovementOutputs struct{}

func (StopMovementOutputs) CommandType

func (StopMovementOutputs) CommandType() CommandType

type UpdateCommandParams

type UpdateCommandParams struct {
	ID             int64
	Status         Status
	SetStatus      bool
	Outputs        Outputs
	SetOutputs     bool
	Error          *string
	SetError       bool
	StartedAt      *time.Time
	SetStartedAt   bool
	CompletedAt    *time.Time
	SetCompletedAt bool
	UpdatedAt      time.Time
}

type WaitInputs

type WaitInputs struct {
	DurationMs int64 `json:"duration_ms" validate:"required"`
}

func (WaitInputs) CommandType

func (WaitInputs) CommandType() CommandType

type WaitOutputs

type WaitOutputs struct{}

func (WaitOutputs) CommandType

func (WaitOutputs) CommandType() CommandType

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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