task

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultGCInitialDelay is the delay time from the start to the first GC execution.
	DefaultGCInitialDelay = 6 * time.Second

	// DefaultGCMetaInterval is the interval time to execute the GC meta.
	DefaultGCMetaInterval = 2 * time.Minute

	// DefaultExpireTime when a task is not accessed within the ExpireTime,
	// and it will be treated to be expired.
	DefaultExpireTime = 30 * time.Minute
)

gc config

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 (
	// DefaultFailAccessInterval is the interval time after failed to access the URL.
	DefaultFailAccessInterval = 3 * time.Minute
)
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 Config added in v2.0.2

type Config struct {
	// GCInitialDelay is the delay time from the start to the first GC execution.
	// default: 6s
	GCInitialDelay time.Duration `yaml:"gcInitialDelay" mapstructure:"gcInitialDelay"`

	// GCMetaInterval is the interval time to execute GC meta.
	// default: 2min
	GCMetaInterval time.Duration `yaml:"gcMetaInterval" mapstructure:"gcMetaInterval"`

	// ExpireTime when a task is not accessed within the ExpireTime,
	// and it will be treated to be expired.
	// default: 3min
	ExpireTime time.Duration `yaml:"taskExpireTime" mapstructure:"taskExpireTime"`

	// FailAccessInterval is the interval time after failed to access the URL.
	// unit: minutes
	// default: 30
	FailAccessInterval time.Duration `yaml:"failAccessInterval" mapstructure:"failAccessInterval"`
}

func DefaultConfig added in v2.0.2

func DefaultConfig() Config

func (Config) Validate added in v2.0.2

func (c Config) Validate() []error

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,sorted by pieceNum ascending order
	GetProgress(taskID string) ([]*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) (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"`
	DownloadCost      uint64            `json:"download_cost"`
	BeginDownloadTime uint64            `json:"begin_download_time"`
	EndDownloadTime   uint64            `json:"end_download_time"`
}

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 *sync.Map `json:"-"` // map[uint32]*PieceInfo

	ExtendAttribute *base.ExtendAttribute `json:"extendAttribute"`
	// 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