Documentation ¶
Index ¶
- Constants
- Variables
- func AckEvent(eventId int) error
- func ApplyAndAckEvent(eventId int, fileKey string, eventType string) error
- func DownloadSyncFile(req SyncFileInfoReq, absPath string) error
- func FindLastEventId() (int, error)
- func InitSchema() error
- func SaveEvent(fe FileEvent) error
- func SyncFileInfoEvents(mode AppMode)
- type AppMode
- type ESStatus
- type EventType
- type FileEvent
- type FileEventSync
- type FileInfo
- type FileType
- type PollEventReq
- type PollEventResp
- type SyncFileInfoReq
- type SyncFileInfoResp
Constants ¶
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" )
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 ¶
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 ApplyAndAckEvent ¶
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 ¶
find last eventId, if none is found, 0 is returned
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 FileEvent ¶
type FileEvent struct { EventId int `json:"eventId"` Type string `json:"type"` FileKey string `json:"fileKey"` }
File event
func FetchEventIdsAfter ¶
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 PollEventReq ¶
type PollEventResp ¶
type SyncFileInfoReq ¶
type SyncFileInfoResp ¶
func FetchSyncFileInfo ¶
func FetchSyncFileInfo(req SyncFileInfoReq) (*SyncFileInfoResp, error)
Fetch info of the file