task

package
v2.0.2-alpha.4 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// StatusWaiting captures enum value "WAITING"
	StatusWaiting string = "WAITING"

	// StatusRunning captures enum value "RUNNING"
	StatusRunning string = "RUNNING"

	// StatusFailed captures enum value "FAILED"
	StatusFailed string = "FAILED"

	// StatusSuccess captures enum value "SUCCESS"
	StatusSuccess string = "SUCCESS"

	// StatusSourceError captures enum value "SOURCE_ERROR"
	StatusSourceError string = "SOURCE_ERROR"
)
View Source
const (
	UnknownTotalPieceCount = -1
)

Variables

This section is empty.

Functions

func IsEqual added in v2.0.2

func IsEqual(task1, task2 SeedTask) bool

func IsSame added in v2.0.2

func IsSame(task1, task2 *SeedTask) bool

IsSame check if task1 is same with task2

func IsTaskNotFound added in v2.0.2

func IsTaskNotFound(err error) bool

Types

type Manager

type Manager interface {

	// AddOrUpdate update existing task info for the key if present.
	// Otherwise, it stores and returns the given value.
	// The isUpdate result is true if the value was updated, false if added.
	AddOrUpdate(registerTask *SeedTask) (seedTask *SeedTask, err error)

	// Get returns the task info with specified taskID, or nil if no
	// value is present.
	// The ok result indicates whether value was found in the taskManager.
	Get(taskID string) (seedTask *SeedTask, err error)

	// Update the task info with specified taskID and updateTask
	Update(taskID string, updateTask *SeedTask) (err error)

	// UpdateProgress update the downloaded pieces belonging to the task
	UpdateProgress(taskID string, piece *PieceInfo) (err error)

	// GetProgress returns the downloaded pieces belonging to the task
	GetProgress(taskID string) (map[uint32]*PieceInfo, error)

	// Exist check task existence with specified taskID.
	// returns the task info with specified taskID, or nil if no value is present.
	// The ok result indicates whether value was found in the taskManager.
	Exist(taskID string) (seedTask *SeedTask, ok bool)

	// Delete a task with specified taskID.
	Delete(taskID string)
}

Manager as an interface defines all operations against SeedTask. A SeedTask will store some meta info about the taskFile, pieces and something else. A seedTask corresponds to three files on the disk, which are identified by taskId, the data file meta file piece file

func NewManager

func NewManager(config *config.Config) (Manager, error)

NewManager returns a new Manager Object.

type PieceInfo added in v2.0.2

type PieceInfo struct {
	PieceNum    uint32            `json:"piece_num"`
	PieceMd5    string            `json:"piece_md5"`
	PieceRange  *rangeutils.Range `json:"piece_range"`
	OriginRange *rangeutils.Range `json:"origin_range"`
	PieceLen    uint32            `json:"piece_len"`
	PieceStyle  base.PieceStyle   `json:"piece_style"`
}

type SeedTask added in v2.0.2

type SeedTask struct {
	// ID of the task
	ID string `json:"ID,omitempty"`

	// RawURL is the resource's URL which user uses dfget to download. The location of URL can be anywhere, LAN or WAN.
	// For image distribution, this is image layer's URL in image registry.
	// The resource url is provided by dfget command line parameter.
	RawURL string `json:"rawURL,omitempty"`

	// TaskURL is generated from rawURL. rawURL may contain some queries or parameter, dfget will filter some queries via
	// --filter parameter of dfget. The usage of it is that different rawURL may generate the same taskID.
	TaskURL string `json:"taskURL,omitempty"`

	// SourceFileLength is the length of the source file in bytes.
	SourceFileLength int64 `json:"sourceFileLength,omitempty"`

	// CdnFileLength is the length of the file stored on CDN
	CdnFileLength int64 `json:"cdnFileLength,omitempty"`

	// PieceSize is the size of pieces in bytes
	PieceSize int32 `json:"pieceSize,omitempty"`

	// CdnStatus is the status of the created task related to CDN functionality.
	//
	// Enum: [WAITING RUNNING FAILED SUCCESS SOURCE_ERROR]
	CdnStatus string `json:"cdnStatus,omitempty"`

	// TotalPieceCount is the total number of pieces
	TotalPieceCount int32 `json:"totalPieceCount,omitempty"`

	// SourceRealDigest when CDN finishes downloading file/image from the source location,
	// the md5 sum of the source file will be calculated as the value of the SourceRealDigest.
	// And it will be used to compare with RequestDigest value to check whether file is complete.
	SourceRealDigest string `json:"sourceRealDigest,omitempty"`

	// PieceMd5Sign Is the SHA256 signature of all pieces md5 signature
	PieceMd5Sign string `json:"pieceMd5Sign,omitempty"`

	// Digest checks integrity of url content, for example md5:xxx or sha256:yyy
	Digest string `json:"digest,omitempty"`

	// Tag identifies different task for same url, conflict with digest
	Tag string `json:"tag,omitempty"`

	// Range content range for url
	Range string `json:"range,omitempty"`

	// Filter url used to generate task id
	Filter string `json:"filter,omitempty"`

	// Header other url header infos
	Header map[string]string `json:"header,omitempty"`

	// Pieces pieces of task
	Pieces map[uint32]*PieceInfo `json:"-"`
	// contains filtered or unexported fields
}

func NewSeedTask added in v2.0.2

func NewSeedTask(taskID string, rawURL string, urlMeta *base.UrlMeta) *SeedTask

func (*SeedTask) Clone added in v2.0.2

func (task *SeedTask) Clone() *SeedTask

func (*SeedTask) IsDone added in v2.0.2

func (task *SeedTask) IsDone() bool

func (*SeedTask) IsError added in v2.0.2

func (task *SeedTask) IsError() bool

IsError if task status if fail

func (*SeedTask) IsFrozen added in v2.0.2

func (task *SeedTask) IsFrozen() bool

IsFrozen if task status is frozen

func (*SeedTask) IsSuccess added in v2.0.2

func (task *SeedTask) IsSuccess() bool

IsSuccess determines that whether the CDNStatus is success.

func (*SeedTask) IsWait added in v2.0.2

func (task *SeedTask) IsWait() bool

IsWait if task status is wait

func (*SeedTask) Log added in v2.0.2

func (task *SeedTask) Log() *logger.SugaredLoggerOnWith

func (*SeedTask) StartTrigger added in v2.0.2

func (task *SeedTask) StartTrigger()

func (*SeedTask) UpdateStatus added in v2.0.2

func (task *SeedTask) UpdateStatus(cdnStatus string)

func (*SeedTask) UpdateTaskInfo added in v2.0.2

func (task *SeedTask) UpdateTaskInfo(cdnStatus, realDigest, pieceMd5Sign string, sourceFileLength, cdnFileLength int64)

Jump to

Keyboard shortcuts

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