new
This commit is contained in:
35
internal/infrastructure/task/interfaces/api_task_queue.go
Normal file
35
internal/infrastructure/task/interfaces/api_task_queue.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package interfaces
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"tyapi-server/internal/infrastructure/task/entities"
|
||||
"tyapi-server/internal/infrastructure/task/types"
|
||||
)
|
||||
|
||||
// ApiTaskQueue API任务队列接口
|
||||
type ApiTaskQueue interface {
|
||||
// Enqueue 入队任务
|
||||
Enqueue(ctx context.Context, taskType types.TaskType, payload types.TaskPayload) error
|
||||
|
||||
// EnqueueDelayed 延时入队任务
|
||||
EnqueueDelayed(ctx context.Context, taskType types.TaskType, payload types.TaskPayload, delay time.Duration) error
|
||||
|
||||
// EnqueueAt 指定时间入队任务
|
||||
EnqueueAt(ctx context.Context, taskType types.TaskType, payload types.TaskPayload, scheduledAt time.Time) error
|
||||
|
||||
// Cancel 取消任务
|
||||
Cancel(ctx context.Context, taskID string) error
|
||||
|
||||
// ModifySchedule 修改任务调度时间
|
||||
ModifySchedule(ctx context.Context, taskID string, newScheduledAt time.Time) error
|
||||
|
||||
// GetTaskStatus 获取任务状态
|
||||
GetTaskStatus(ctx context.Context, taskID string) (*entities.AsyncTask, error)
|
||||
|
||||
// ListTasks 列出任务
|
||||
ListTasks(ctx context.Context, taskType types.TaskType, status entities.TaskStatus, limit int) ([]*entities.AsyncTask, error)
|
||||
|
||||
// EnqueueTask 入队任务(简化版本)
|
||||
EnqueueTask(ctx context.Context, task *entities.AsyncTask) error
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package interfaces
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
"tyapi-server/internal/infrastructure/task/entities"
|
||||
"tyapi-server/internal/infrastructure/task/types"
|
||||
)
|
||||
|
||||
// ArticleTaskQueue 文章任务队列接口
|
||||
type ArticleTaskQueue interface {
|
||||
// Enqueue 入队任务
|
||||
Enqueue(ctx context.Context, taskType types.TaskType, payload types.TaskPayload) error
|
||||
|
||||
// EnqueueDelayed 延时入队任务
|
||||
EnqueueDelayed(ctx context.Context, taskType types.TaskType, payload types.TaskPayload, delay time.Duration) error
|
||||
|
||||
// EnqueueAt 指定时间入队任务
|
||||
EnqueueAt(ctx context.Context, taskType types.TaskType, payload types.TaskPayload, scheduledAt time.Time) error
|
||||
|
||||
// Cancel 取消任务
|
||||
Cancel(ctx context.Context, taskID string) error
|
||||
|
||||
// ModifySchedule 修改任务调度时间
|
||||
ModifySchedule(ctx context.Context, taskID string, newScheduledAt time.Time) error
|
||||
|
||||
// GetTaskStatus 获取任务状态
|
||||
GetTaskStatus(ctx context.Context, taskID string) (*entities.AsyncTask, error)
|
||||
|
||||
// ListTasks 列出任务
|
||||
ListTasks(ctx context.Context, taskType types.TaskType, status entities.TaskStatus, limit int) ([]*entities.AsyncTask, error)
|
||||
}
|
||||
44
internal/infrastructure/task/interfaces/task_manager.go
Normal file
44
internal/infrastructure/task/interfaces/task_manager.go
Normal file
@@ -0,0 +1,44 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user