Help us shape the future of Go! Take the 2026 Go Developer Survey

queue

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const CName = "any-ns.queue"

Variables

This section is empty.

Functions

func New

func New() app.ComponentRunnable

func StatusToState

func StatusToState(status QueueItemStatus) nsp.OperationState

Types

type QueueItem

type QueueItem struct {
	Index           int64         `bson:"index"`
	ItemType        QueueItemType `bson:"itemType"`
	FullName        string        `bson:"fullName"`
	OwnerAnyAddress string        `bson:"ownerAnyAddress"`
	OwnerEthAddress string        `bson:"ownerEthAddress"`
	SpaceId         string        `bson:"spaceId"`
	// aux fields
	SecretBase64         string          `bson:"secretBase64"`
	Status               QueueItemStatus `bson:"status"`
	TxCommitHash         string          `bson:"txCommitHash"`
	TxCommitNonce        uint64          `bson:"txCommitNonce"`
	TxRegisterHash       string          `bson:"txRegisterHash"`
	TxRegisterNonce      uint64          `bson:"txRegisterNonce"`
	DateCreated          int64           `bson:"dateCreated"`
	DateModified         int64           `bson:"dateModified"`
	RegisterPeriodMonths uint32          `bson:"registerPeriodMonths"`

	// for ItemType_NameRenew
	TxRenewCommitHash string `bson:"txRenewCommitHash"`

	TxCurrentNonce uint64 `bson:"currentTxNonce"`
	TxCurrentRetry uint   `bson:"currentTxRetry"`
}

this structure is saved to mem queue and to DB

type QueueItemStatus

type QueueItemStatus int32
const (
	OperationStatus_Initial    QueueItemStatus = 0
	OperationStatus_CommitSent QueueItemStatus = 1
	OperationStatus_CommitDone QueueItemStatus = 2

	OperationStatus_RegisterSent QueueItemStatus = 3
	OperationStatus_Completed    QueueItemStatus = 4

	OperationStatus_CommitError   QueueItemStatus = 5
	OperationStatus_RegisterError QueueItemStatus = 6

	OperationStatus_Error QueueItemStatus = 7
)

when adding new status, don't forget to update these function: 1. StatusToState 2. NameRegisterMoveStateNext (IsStopProcessing in some rare cases)

type QueueItemType

type QueueItemType int32
const (
	ItemType_NameRegister QueueItemType = 1
	ItemType_NameRenew    QueueItemType = 2
)

type QueueService

type QueueService interface {
	// 1 - new name registration request
	AddNewRequest(ctx context.Context, req *nsp.NameRegisterRequest) (operationId int64, err error)
	GetRequestStatus(ctx context.Context, operationId int64) (status nsp.OperationState, err error)

	// Internal methods (public for tests):
	// read all "pending" items from DB and try to process em during startup
	FindAndProcessAllItemsInDb(ctx context.Context)
	FindAndProcessAllItemsInDbWithStatus(ctx context.Context, status QueueItemStatus)
	SaveItemToDb(ctx context.Context, queueItem *QueueItem) error

	// process 1 item and update its state in the DB
	ProcessItem(ctx context.Context, queueItem *QueueItem) error

	// NameRegister functions and states:
	// TODO: refactor - move to separate file
	NameRegisterMoveStateNext(ctx context.Context, queueItem *QueueItem) (newState QueueItemStatus, err error)

	app.ComponentRunnable
}

Directories

Path Synopsis
Package mock_queue is a generated GoMock package.
Package mock_queue is a generated GoMock package.

Jump to

Keyboard shortcuts

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