Documentation ¶
Index ¶
- Constants
- Variables
- func AckWhen(i AckWhenStatus)
- func ArgsMapToStruct(am ArgsMap, s interface{}) error
- func NewConcurrencyLimiter(limit int) *concurrencyLimiter
- func Register(jobName string, handlers ...JobHandler)
- func Run(ctx context.Context, nproc int, queueNames ...string)
- func UseRedisBroker(redisURL string, brokerOptions ...RedisBrokerOption) error
- type AckWhenStatus
- type ArgsMap
- type Broker
- type JobHandler
- type Queue
- type QueueOption
- type RedisBroker
- type RedisBrokerOption
- type ReentrantOption
- type ReentrantOptions
- type Task
Constants ¶
View Source
const ( CREATED = "created" ACQUIRED = "acquired" ENQUEUED = "enqeued" RUNNING = "running" FAILED = "failed" SUCESSED = "sucessed" FINISHED = "finished" )
Variables ¶
View Source
var (
// gotasks builtin queue
FatalQueueName = "fatal"
)
Functions ¶
func ArgsMapToStruct ¶
ArgsMapToStruct Convert ArgsMap to struct, e.g. err := ArgsMapToStruct(am, &yourStruct)
func Register ¶
func Register(jobName string, handlers ...JobHandler)
func UseRedisBroker ¶
func UseRedisBroker(redisURL string, brokerOptions ...RedisBrokerOption) error
Types ¶
type AckWhenStatus ¶
type AckWhenStatus int
gotasks is a job/task framework for Golang.
Note that job will be executed in register order, and every job handle function must have a signature which match gotasks.JobHandler, which receives a ArgsMap and return a ArgsMap which will be arguments input for next handler.
const ( AckWhenAcquired AckWhenStatus = iota AckWhenSucceed )
type ArgsMap ¶
type ArgsMap map[string]interface{}
func MapToArgsMap ¶
func MapToArgsMap(v interface{}) ArgsMap
MapToArgsMap Convert golang map to ArgsMap, e.g. am := MapToArgsMap(yourStruct)
func StructToArgsMap ¶
func StructToArgsMap(v interface{}) ArgsMap
StructToArgsMap Convert struct to ArgsMap, e.g. am := StructToArgsMap(yourStruct)
type JobHandler ¶
func Reentrant ¶
func Reentrant(handler JobHandler, options ...ReentrantOption) JobHandler
type QueueOption ¶
type QueueOption func(*Queue)
func WithAsyncHandleTask ¶
func WithAsyncHandleTask(async bool) QueueOption
func WithMaxLimit ¶
func WithMaxLimit(max int) QueueOption
func WithMonitorInterval ¶
func WithMonitorInterval(seconds int) QueueOption
type RedisBroker ¶
type RedisBroker struct {
TaskTTL int
}
func (*RedisBroker) Ack ¶
func (r *RedisBroker) Ack(task *Task) bool
func (*RedisBroker) Enqueue ¶
func (r *RedisBroker) Enqueue(task *Task) string
func (*RedisBroker) QueueLen ¶
func (r *RedisBroker) QueueLen(queueName string) int64
func (*RedisBroker) Update ¶
func (r *RedisBroker) Update(task *Task) error
type RedisBrokerOption ¶
type RedisBrokerOption func(rb *RedisBroker)
func WithRedisTaskTTL ¶
func WithRedisTaskTTL(ttl int) RedisBrokerOption
type ReentrantOption ¶
type ReentrantOption func(*ReentrantOptions)
func WithMaxTimes ¶
func WithMaxTimes(max int) ReentrantOption
func WithSleepyMS ¶
func WithSleepyMS(ms int) ReentrantOption
type ReentrantOptions ¶
type Task ¶
type Task struct { ID string `json:"task_id"` //任务ID CreatedAt time.Time `json:"created_at"` // 创建任务的时间 UpdatedAt time.Time `json:"updated_at"` // 最近一次更新任务的时间 QueueName string `json:"queue_name"` // 任务队列的名字 JobName string `json:"job_name"` // 任务的名称 ResultArgsMap ArgsMap `json:"result_args_map"` // 任务执行结果的map CurrentHandlerIndex int `json:"current_handler_index"` // 当前任务所在task执行队列的索引id OriginalArgsMap ArgsMap `json:"original_args_map"` // 从消息队列请求的参数map ResultLog string `json:"result_log"` // 返回的 Status status `json:"status"` // 任务的当前状态 Errlog string `json:"err_log"` //任务的错误结果日志 }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.