domain

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// event is fetched, but not acked
	ES_FETCHED ESStatus = "FETCHED"

	// event is fetched and acked
	ES_ACKED ESStatus = "ACKED"

	// limit of eventIds fetched
	FETCH_LIMIT int = 30

	// AppMode: standalone mode
	AM_STANDALONE AppMode = "STANDALONE"

	// AppMode: cluster mode
	AM_CLUSTER AppMode = "CLUSTER"

	PROP_FILE_BASE = "file.base"
)
View Source
const (

	// EventType: file uploaded
	ET_FILE_ADDED EventType = "UPLOADED"
	// EventType: file deleted
	ET_FILE_DELETED EventType = "DELETED"

	/*
		--------------------------------

		Props

		--------------------------------
	*/
	PROP_SYNC_SECRET      = "client.secret"
	PROP_FILE_SERVICE_URL = "client.fileServiceUrl"

	/*
		--------------------------------

		File Type

		--------------------------------
	*/
	// FileType file
	FT_FILE FileType = "FILE"
	// FileType directory
	FT_DIR FileType = "DIR"
)

Variables

View Source
var (
	ErrMissingSecret = errors.New("missing secret for event sync")
	ErrMissingUrl    = errors.New("missing client.fileServiceUrl configuration, unable to resolve base url for file-service")
)

Functions

func AckEvent

func AckEvent(eventId int) error

ack the event

func ApplyAndAckEvent

func ApplyAndAckEvent(eventId int, fileKey string, eventType string) error

Apply and ack event

This func always tries to apply the event and ack it as if it has never been applied before. Even if it found the file on disk, the downloaded file may be imcomplete or corrupted, the file is always truncated and re-downloaded.

func DownloadSyncFile

func DownloadSyncFile(req SyncFileInfoReq, absPath string) error

Fetch info of the file

func FindLastEventId

func FindLastEventId() (int, error)

find last eventId, if none is found, 0 is returned

func InitSchema

func InitSchema() error

Create schema if absent

func SaveEvent

func SaveEvent(fe FileEvent) error

Save event

func SyncFileInfoEvents

func SyncFileInfoEvents(mode AppMode)

sync file events, events must be sync in order one by one, if any failed, we start it over unless the last event is acked

Types

type AppMode

type AppMode string

App mode (server / standalone)

if server mode is selected, then redis must be deployed for distributed locking

if standalone mode is selected, then it will simply used mutex lock for syncing

type ESStatus

type ESStatus string

event sync status

type EventType

type EventType string

Event type

type FileEvent

type FileEvent struct {
	EventId int    `json:"eventId"`
	Type    string `json:"type"`
	FileKey string `json:"fileKey"`
}

File event

func FetchEventIdsAfter

func FetchEventIdsAfter(lastEventId int) ([]FileEvent, error)

fetch eventIds after the lastEventId

type FileEventSync

type FileEventSync struct {
	Id         int
	EventId    int
	FileKey    string
	EventType  string
	SyncStatus ESStatus
	FetchTime  time.Time
	AckTime    time.Time
	CreateTime time.Time
	CreateBy   string
	UpdateTime time.Time
	UpdateBy   string
	IsDel      common.IS_DEL
}

file event synchronization and acknowledgement

func FindLastNonAckedEvent

func FindLastNonAckedEvent() (FileEventSync, error)

Find last fetched eventId, if none is found, a FileEventSync with 'zero value' is returned

type FileInfo

type FileInfo struct {
	Name         *string
	Uuid         *string
	SizeInBytes  *int64
	IsDeleted    *bool
	UploaderId   *int
	UploaderName *string
	UserGroup    *int
	FileType     *string
	ParentFile   *string
}

type FileType

type FileType string

File type

type PollEventReq

type PollEventReq struct {
	EventId int    `json:"eventId"`
	Limit   int    `json:"limit"`
	Secret  string `json:"secret"`
}

type PollEventResp

type PollEventResp struct {
	common.Resp
	Data []FileEvent `json:"data"`
}

func PollEvents

func PollEvents(req PollEventReq) (*PollEventResp, error)

Poll Events

type SyncFileInfoReq

type SyncFileInfoReq struct {
	FileKey string `json:"fileKey"`
	Secret  string `json:"secret"`
}

type SyncFileInfoResp

type SyncFileInfoResp struct {
	common.Resp
	Data *FileInfo `json:"data"`
}

func FetchSyncFileInfo

func FetchSyncFileInfo(req SyncFileInfoReq) (*SyncFileInfoResp, error)

Fetch info of the file

Jump to

Keyboard shortcuts

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