2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-25 07:12:17 +08:00

[ci skip] Update docs

This commit is contained in:
Ken Hibino 2020-01-16 19:50:45 -08:00
parent 43d7591250
commit 0c2591ad7e
5 changed files with 26 additions and 23 deletions

View File

@ -16,14 +16,14 @@ type Task struct {
// Type indicates the type of task to be performed. // Type indicates the type of task to be performed.
Type string Type string
// Payload holds data needed to process the task. // Payload holds data needed to perform the task.
Payload Payload Payload Payload
} }
// NewTask returns a new instance of a task given a task type and payload. // NewTask returns a new Task. The typename and payload argument set Type
// and Payload field respectively.
// //
// Since payload data gets serialized to JSON, the payload values must be // The payload must be serializable to JSON.
// composed of JSON supported data types.
func NewTask(typename string, payload map[string]interface{}) *Task { func NewTask(typename string, payload map[string]interface{}) *Task {
return &Task{ return &Task{
Type: typename, Type: typename,
@ -34,17 +34,20 @@ func NewTask(typename string, payload map[string]interface{}) *Task {
// RedisConnOpt is a discriminated union of redis-client-option types. // RedisConnOpt is a discriminated union of redis-client-option types.
// //
// RedisConnOpt represents a sum of following types: // RedisConnOpt represents a sum of following types:
//
// RedisClientOpt | *RedisClientOpt | RedisFailoverClientOpt | *RedisFailoverClientOpt // RedisClientOpt | *RedisClientOpt | RedisFailoverClientOpt | *RedisFailoverClientOpt
//
// Passing unexpected type to a RedisConnOpt variable can cause panic.
type RedisConnOpt interface{} type RedisConnOpt interface{}
// RedisClientOpt is used to specify redis client options to connect // RedisClientOpt is used to create a redis client that connects
// to a redis server running as a stand alone instance. // to a redis server directly.
type RedisClientOpt struct { type RedisClientOpt struct {
// Network type to use, either tcp or unix. // Network type to use, either tcp or unix.
// Default is tcp. // Default is tcp.
Network string Network string
// Redis server address in the format 'host:port'. // Redis server address in "host:port" format.
Addr string Addr string
// Redis server password. // Redis server password.
@ -63,12 +66,14 @@ type RedisClientOpt struct {
TLSConfig *tls.Config TLSConfig *tls.Config
} }
// RedisFailoverClientOpt is used to specify redis failover client. // RedisFailoverClientOpt is used to creates a redis client that talks
// to redis sentinels for service discovery and has automatic failover
// capability.
type RedisFailoverClientOpt struct { type RedisFailoverClientOpt struct {
// Redis master name that monitored by sentinels. // Redis master name that monitored by sentinels.
MasterName string MasterName string
// Addresses of sentinels in the form "host:port". // Addresses of sentinels in "host:port" format.
// Use at least three sentinels to avoid problems described in // Use at least three sentinels to avoid problems described in
// https://redis.io/topics/sentinel. // https://redis.io/topics/sentinel.
SentinelAddrs []string SentinelAddrs []string

View File

@ -21,10 +21,10 @@ import (
// Background is responsible for managing the background-task processing. // Background is responsible for managing the background-task processing.
// //
// Background manages background queues to process tasks and retry if // Background manages task queues to process tasks.
// necessary. If the processing of a task is unsuccessful, background will // If the processing of a task is unsuccessful, background will
// schedule it for a retry with an exponential backoff until either the task // schedule it for a retry until either the task gets processed successfully
// gets processed successfully or it exhausts its max retry count. // or it exhausts its max retry count.
// //
// Once a task exhausts its retries, it will be moved to the "dead" queue and // Once a task exhausts its retries, it will be moved to the "dead" queue and
// will be kept in the queue for some time until a certain condition is met // will be kept in the queue for some time until a certain condition is met
@ -41,7 +41,7 @@ type Background struct {
// Config specifies the background-task processing behavior. // Config specifies the background-task processing behavior.
type Config struct { type Config struct {
// Maximum number of concurrent workers to process tasks. // Maximum number of concurrent processing of tasks.
// //
// If set to zero or negative value, NewBackground will overwrite the value to one. // If set to zero or negative value, NewBackground will overwrite the value to one.
Concurrency int Concurrency int
@ -92,7 +92,7 @@ var defaultQueueConfig = map[string]uint{
base.DefaultQueueName: 1, base.DefaultQueueName: 1,
} }
// NewBackground returns a new Background instance given a redis client // NewBackground returns a new Background given a redis connection option
// and background processing configuration. // and background processing configuration.
func NewBackground(r RedisConnOpt, cfg *Config) *Background { func NewBackground(r RedisConnOpt, cfg *Config) *Background {
n := cfg.Concurrency n := cfg.Concurrency

View File

@ -23,13 +23,13 @@ type Client struct {
rdb *rdb.RDB rdb *rdb.RDB
} }
// NewClient and returns a new Client given a redis configuration. // NewClient and returns a new Client given a redis connection option.
func NewClient(r RedisConnOpt) *Client { func NewClient(r RedisConnOpt) *Client {
rdb := rdb.NewRDB(createRedisClient(r)) rdb := rdb.NewRDB(createRedisClient(r))
return &Client{rdb} return &Client{rdb}
} }
// Option specifies the processing behavior for the associated task. // Option specifies the task processing behavior.
type Option interface{} type Option interface{}
// Internal option representations. // Internal option representations.
@ -49,7 +49,7 @@ func MaxRetry(n int) Option {
return retryOption(n) return retryOption(n)
} }
// Queue returns an option to specify which queue to enqueue the task into. // Queue returns an option to specify the queue to enqueue the task into.
// //
// Queue name is case-insensitive and the lowercased version is used. // Queue name is case-insensitive and the lowercased version is used.
func Queue(name string) Option { func Queue(name string) Option {
@ -87,10 +87,10 @@ const (
// Schedule registers a task to be processed at the specified time. // Schedule registers a task to be processed at the specified time.
// //
// Schedule returns nil if the task is registered successfully, // Schedule returns nil if the task is registered successfully,
// otherwise returns non-nil error. // otherwise returns a non-nil error.
// //
// opts specifies the behavior of task processing. If there are conflicting // opts specifies the behavior of task processing. If there are conflicting
// Option the last one overrides the ones before. // Option values the last one overrides others.
func (c *Client) Schedule(task *Task, processAt time.Time, opts ...Option) error { func (c *Client) Schedule(task *Task, processAt time.Time, opts ...Option) error {
opt := composeOptions(opts...) opt := composeOptions(opts...)
msg := &base.TaskMessage{ msg := &base.TaskMessage{

2
doc.go
View File

@ -50,8 +50,6 @@ Example of a type that implements the Handler interface.
case "send_email": case "send_email":
id, err := task.Payload.GetInt("user_id") id, err := task.Payload.GetInt("user_id")
// send email // send email
case "generate_thumbnail":
// generate thumbnail image
//... //...
default: default:
return fmt.Errorf("unexpected task type %q", task.Type) return fmt.Errorf("unexpected task type %q", task.Type)

View File

@ -11,7 +11,7 @@ import (
"github.com/spf13/cast" "github.com/spf13/cast"
) )
// Payload is an arbitrary data needed for task execution. // Payload holds arbitrary data needed for task execution.
type Payload struct { type Payload struct {
data map[string]interface{} data map[string]interface{}
} }