45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
|
|
package interfaces
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"tyapi-server/internal/infrastructure/task/entities"
|
||
|
|
)
|
||
|
|
|
||
|
|
// TaskManager 任务管理器接口
|
||
|
|
// 统一管理Asynq任务和AsyncTask实体的操作
|
||
|
|
type TaskManager interface {
|
||
|
|
// 创建并入队任务
|
||
|
|
CreateAndEnqueueTask(ctx context.Context, task *entities.AsyncTask) error
|
||
|
|
|
||
|
|
// 创建并入队延时任务
|
||
|
|
CreateAndEnqueueDelayedTask(ctx context.Context, task *entities.AsyncTask, delay time.Duration) error
|
||
|
|
|
||
|
|
// 取消任务
|
||
|
|
CancelTask(ctx context.Context, taskID string) error
|
||
|
|
|
||
|
|
// 更新任务调度时间
|
||
|
|
UpdateTaskSchedule(ctx context.Context, taskID string, newScheduledAt time.Time) error
|
||
|
|
|
||
|
|
// 获取任务状态
|
||
|
|
GetTaskStatus(ctx context.Context, taskID string) (*entities.AsyncTask, error)
|
||
|
|
|
||
|
|
// 更新任务状态
|
||
|
|
UpdateTaskStatus(ctx context.Context, taskID string, status entities.TaskStatus, errorMsg string) error
|
||
|
|
|
||
|
|
// 重试任务
|
||
|
|
RetryTask(ctx context.Context, taskID string) error
|
||
|
|
|
||
|
|
// 清理过期任务
|
||
|
|
CleanupExpiredTasks(ctx context.Context, olderThan time.Time) error
|
||
|
|
}
|
||
|
|
|
||
|
|
// TaskManagerConfig 任务管理器配置
|
||
|
|
type TaskManagerConfig struct {
|
||
|
|
RedisAddr string
|
||
|
|
MaxRetries int
|
||
|
|
RetryInterval time.Duration
|
||
|
|
CleanupDays int
|
||
|
|
}
|