client

package
v1.1.0-beta.0...-cc83417 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CmdRequest

type CmdRequest struct {
	RequestID string          `json:"request_id"`
	CmdType   string          `json:"cmd_type"`
	Data      json.RawMessage `json:"data"`
}

CmdRequest is the request for a TTL command

func (*CmdRequest) GetTriggerTTLJobRequest

func (r *CmdRequest) GetTriggerTTLJobRequest() (*TriggerNewTTLJobRequest, bool)

GetTriggerTTLJobRequest returns the `TriggerNewTTLJobRequest` object if command type is 'trigger_ttl_job', otherwise, (nil, false) will be returned

type CommandClient

type CommandClient interface {
	// Command sends a command and waits for response. The first value of the return is the requestID, it always not empty.
	Command(ctx context.Context, cmdType string, obj any, response any) (string, error)
	// WatchCommand watches the commands that are sent
	WatchCommand(ctx context.Context) <-chan *CmdRequest
	// TakeCommand takes a command to ensure only one can handle the command.
	// If the first return value is true, it means you have taken the command successfully,
	// and you should call `ResponseCommand`
	// after processed the command. Otherwise, you should not process this command because it is not belong to you.
	TakeCommand(ctx context.Context, reqID string) (bool, error)
	// ResponseCommand responses the result of the command. `TakeCommand` must be called first before `ResponseCommand`
	// obj is the response object to the sender, if obj is an error, the sender will receive an error too.
	ResponseCommand(ctx context.Context, reqID string, obj any) error
}

CommandClient is an interface used to send and response command of TTL jobs

func NewCommandClient

func NewCommandClient(etcdCli *clientv3.Client) CommandClient

NewCommandClient creates a command client with etcd

func NewMockCommandClient

func NewMockCommandClient() CommandClient

NewMockCommandClient creates a mock command client

type NotificationClient

type NotificationClient interface {
	// Notify sends a notification
	Notify(ctx context.Context, typ string, data string) error
	// WatchNotification opens a channel, in which we could receive all notifications
	WatchNotification(ctx context.Context, typ string) clientv3.WatchChan
}

NotificationClient is a client to notify other TTL workers

func NewMockNotificationClient

func NewMockNotificationClient() NotificationClient

NewMockNotificationClient creates a mock notification client

func NewNotificationClient

func NewNotificationClient(etcdCli *clientv3.Client) NotificationClient

NewNotificationClient creates a notification client with etcd

type TriggerNewTTLJobRequest

type TriggerNewTTLJobRequest struct {
	DBName    string `json:"db_name"`
	TableName string `json:"table_name"`
}

TriggerNewTTLJobRequest is the command detail to trigger a TTL job

type TriggerNewTTLJobResponse

type TriggerNewTTLJobResponse struct {
	TableResult []*TriggerNewTTLJobTableResult `json:"table_result"`
}

TriggerNewTTLJobResponse is the response detail for trigger_ttl_job command

func TriggerNewTTLJob

func TriggerNewTTLJob(ctx context.Context, cli CommandClient, dbName, tableName string) (
	*TriggerNewTTLJobResponse, error)

TriggerNewTTLJob triggers a new TTL job

type TriggerNewTTLJobTableResult

type TriggerNewTTLJobTableResult struct {
	TableID       int64  `json:"table_id"`
	DBName        string `json:"db_name"`
	TableName     string `json:"table_name"`
	PartitionName string `json:"partition_name,omitempty"`
	JobID         string `json:"job_id,omitempty"`
	ErrorMessage  string `json:"error_message,omitempty"`
}

TriggerNewTTLJobTableResult is the table detail of `TriggerNewTTLJobResponse`

Jump to

Keyboard shortcuts

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