l-export-async/task.go

36 lines
683 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package l_export_async
import (
"context"
"time"
)
type TaskInfo struct {
taskSaveTool TaskSaveTool // 任务状态存储(如 Redis
}
type TaskErr interface {
Err() error
}
type TaskGet interface {
TaskErr
Val() string
}
type TaskSaveTool interface {
Set(ctx context.Context, key string, value interface{}, expiration time.Duration) TaskErr
Del(ctx context.Context, keys ...string) TaskErr
Get(ctx context.Context, key string) TaskGet
}
func NewTask(taskSaveTool TaskSaveTool) *TaskInfo {
return &TaskInfo{
taskSaveTool: taskSaveTool,
}
}
func (t *TaskInfo) GetTaskInfo(ctx context.Context, taskId string) TaskGet {
return t.taskSaveTool.Get(ctx, taskId)
}