taskstore

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TaskTypeDownload = "下载"
)

Variables

This section is empty.

Functions

func BuildIdentitySHA1

func BuildIdentitySHA1(parts ...string) string

BuildIdentitySHA1 根据输入片段生成幂等用的 identity。

func Cancel

func Cancel(ctx context.Context, taskID string) error

func ClaimOrCreate

func ClaimOrCreate(ctx context.Context, typ, identity, id string, totalBytes int64, data any) (taskID string, attached bool, err error)

ClaimOrCreate 尝试以 identity 附着到已有运行任务;若不存在或已陈旧则创建/接管。 attached==true 表示已存在活跃任务,调用方不应重复启动,而是提示用户查看状态。

func Complete

func Complete(ctx context.Context, taskID string) error

func Fail

func Fail(ctx context.Context, taskID string, errMsg string) error

func Get

func Get(ctx context.Context, taskID string) (*model.Task, error)

func Heartbeat

func Heartbeat(ctx context.Context, taskID string, hb HeartbeatData) (cancelRequested bool, err error)

func ListRunning

func ListRunning(ctx context.Context) ([]model.Task, error)

func SetCanceled

func SetCanceled(ctx context.Context, taskID string) error

Types

type DownloadData

type DownloadData struct {
	FSID       uint64 `json:"fsid,omitempty"`
	Path       string `json:"path"`
	MD5        string `json:"md5,omitempty"`
	OutputDir  string `json:"output_dir,omitempty"`
	TargetPath string `json:"target_path,omitempty"`
	IsDir      bool   `json:"is_dir"`
}

type HeartbeatData

type HeartbeatData struct {
	DownloadedBytes int64
	TotalBytes      int64
	Progress        float64
	SpeedBPS        int64
	ETASeconds      int64
}

Jump to

Keyboard shortcuts

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