Documentation
¶
Index ¶
- Variables
- type ExportCenter
- func (ec *ExportCenter) CompleteTask(id, writeNum int64) error
- func (ec *ExportCenter) ConsultTask(id int64) error
- func (ec *ExportCenter) CreateTask(key, name, description, source, destination, format string, count int64, ...) (uint, []string, error)
- func (ec *ExportCenter) ExportToExcel(id int64, filePath string, before func(key string) error) (err error)
- func (ec *ExportCenter) FailTask(id int64, errNum, writeNum int64) error
- func (ec *ExportCenter) GetTask(id int64) (info Task, err error)
- func (ec *ExportCenter) PopData(key string) <-chan string
- func (ec *ExportCenter) PushData(key string, data string) error
- func (ec *ExportCenter) StartTask(id int64)
- func (ec *ExportCenter) UpdateTaskDownloadUrl(id int64, url string) error
- func (ec *ExportCenter) UpdateTaskErrLogUrl(id int64, url string) error
- type ExportOptions
- type Options
- type Queue
- type Task
- func (m *Task) CompleteTaskByID(id int64, writeNum int64) error
- func (m *Task) Create() error
- func (m *Task) FailTaskByID(id int64, errNum, writeNum int64) error
- func (m *Task) FindByID(id int64) (info Task, err error)
- func (m *Task) UpdateDownloadUrlByID(id int64, url string) error
- func (m *Task) UpdateErrLogUrlByID(id int64, url string) error
- func (m *Task) UpdateStatusByID(id int64, status TaskStatus) error
- type TaskStatus
Constants ¶
This section is empty.
Variables ¶
View Source
var DbClient *gorm.DB
Functions ¶
This section is empty.
Types ¶
type ExportCenter ¶
func NewClient ¶
func NewClient(options Options) (*ExportCenter, error)
func (*ExportCenter) CompleteTask ¶
func (ec *ExportCenter) CompleteTask(id, writeNum int64) error
CompleteTask 完成任务
func (*ExportCenter) ConsultTask ¶
func (ec *ExportCenter) ConsultTask(id int64) error
ConsultTask 任务进行中
func (*ExportCenter) CreateTask ¶
func (ec *ExportCenter) CreateTask(key, name, description, source, destination, format string, count int64, options ExportOptions) (uint, []string, error)
CreateTask 创建导出任务
func (*ExportCenter) ExportToExcel ¶
func (ec *ExportCenter) ExportToExcel(id int64, filePath string, before func(key string) error) (err error)
ExportToExcel 导出成excel表格,格式
func (*ExportCenter) FailTask ¶
func (ec *ExportCenter) FailTask(id int64, errNum, writeNum int64) error
FailTask 任务失败
func (*ExportCenter) GetTask ¶
func (ec *ExportCenter) GetTask(id int64) (info Task, err error)
GetTask 获取任务信息
func (*ExportCenter) PopData ¶
func (ec *ExportCenter) PopData(key string) <-chan string
PopData 拉取队列数据
func (*ExportCenter) PushData ¶
func (ec *ExportCenter) PushData(key string, data string) error
PushData 推送导出数据到队列
func (*ExportCenter) UpdateTaskDownloadUrl ¶
func (ec *ExportCenter) UpdateTaskDownloadUrl(id int64, url string) error
UpdateTaskDownloadUrl 更新任务文件下载链接
func (*ExportCenter) UpdateTaskErrLogUrl ¶
func (ec *ExportCenter) UpdateTaskErrLogUrl(id int64, url string) error
UpdateTaskErrLogUrl 更新错误日志地址
type ExportOptions ¶
type ExportOptions struct {
FileName string `json:"file_name"` // 文件名称
Header []string `json:"header"` // 表头配置
}
ExportOptions 导出选项
type Options ¶
type Options struct {
Db *gorm.DB // gorm实例
QueuePrefix string // 队列前缀
Queue Queue // 队列配置(必须配置)
SheetMaxRows int64 // 数据表最大行数,用于生成队列key,可以用不同的队列同时并发写入数据,队列数量由【任务数据量】/【数据表最大行数】计算所得
PoolMax int // 协程池最大数量
GoroutineMax int // 协程最大数量
IsUploadCloud bool // 是否上传云端
Upload func(filePath string) (string, error) // 上传接口
LogRootPath string // 日志存储根目录
OutTime time.Duration // 超时时间
}
Options 配置
type Queue ¶
type Queue interface {
CreateQueue(ctx context.Context, key string) error // 创建队列
Pop(ctx context.Context, key string) <-chan string // 拉取数据
Push(ctx context.Context, key string, data string) error // 推送数据
Destroy(ctx context.Context, key string) error // 删除队列
}
Queue 队列
type Task ¶
type Task struct {
gorm.Model
Name string `gorm:"type:varchar(255);comment:'任务名称'"`
Description string `gorm:"type:text;comment:'描述'"`
Status int `gorm:"type:tinyint(1);default:1;comment:'状态 1-待处理、2-处理中、3-已完成、4-失败、5-任务废弃'"`
ProgressRate int `gorm:"type:tinyint(3);default:0;comment:'任务进度1-100'"`
StartTime sql.NullTime `gorm:"type:datetime;comment:'任务开始时间'"`
EndTime sql.NullTime `gorm:"type:datetime;comment:'任务结束时间'"`
Source string `gorm:"type:varchar(255);comment:'数据源,描述导出数据的来源'"`
Destination string `gorm:"type:varchar(255);comment:'数据目标,描述导出数据的存储位置'"`
ExportFormat string `gorm:"type:varchar(255);comment:'导出格式,如CSV、JSON、XML等'"`
ExportOptions string `gorm:"type:text;comment:'导出选项,可存储导出任务的配置信息(可选)'"`
QueueKey string `gorm:"type:varchar(255);comment:'队列key'"`
CountNum int64 `gorm:"type:int(11);default:0;comment:'数据总数'"`
WriteNum int64 `gorm:"type:int(11);default:0;comment:'已写入数据数量'"`
ErrNum int64 `gorm:"type:int(11);default:0;comment:'错误数据数'"`
ErrLogUrl string `gorm:"type:text;comment:'错误日志地址'"`
DownloadUrl string `gorm:"type:text;comment:'文件下载地址'"`
}
Task 任务表 用于记录所有的到处任务以及导出状态
func (*Task) UpdateDownloadUrlByID ¶
func (*Task) UpdateStatusByID ¶
func (m *Task) UpdateStatusByID(id int64, status TaskStatus) error
type TaskStatus ¶
type TaskStatus int
const ( TaskStatusWait TaskStatus = 1 TaskStatusConsult TaskStatus = 2 TaskStatusCompleted TaskStatus = 3 TaskStatusFail TaskStatus = 4 TaskStatusAbandon TaskStatus = 5 )
func (TaskStatus) ParseInt ¶
func (s TaskStatus) ParseInt() int
Click to show internal directories.
Click to hide internal directories.