modulepackage
0.0.6
Repository: https://github.com/stellaraf/go-task-queue.git
Documentation: pkg.go.dev
# README
Usage
Basic Task Queue
BasicTaskQueue
is a simple task queue that stores tasks as strings.
queue, err := taskqueue.NewBasic("queue-name")
queue.Add("example1", "example2")
value := queue.Pop()
// example1
value = queue.Pop()
// example2
JSON Task Queue
JSONTaskQueue
provides a very similar API to BasicTaskQueue
and has the ability to store virtually any objet type as a task.
type Data struct {
System string
Count int
}
type Task struct {
ID string `json:"id"`
Details []string `json:"details"`
Timestamp time.Time `json:"timestamp"`
Data *Data `json:"data"`
}
task := Task{
ID: "1234",
Details: []string{"some", "details"},
Timestamp: time.Now(),
Data: &Data{System: "aws", Count: 5},
}
queue, err := taskqueue.NewJSON("queue-name")
queue.Add(task)
var fromQueue *Task
queue.Pop(&fromQueue)
Options
Both BasicTaskQueue
and JSONTaskQueue
support the same options:
taskqueue.NewBasic(
"queue-name",
// Use a Redis connection string instead of WithHost/WithUsername/WithPassword.
taskqueue.WithURI("redis://redis-username:[email protected]:55032"),
// Set the Redis hostname. By default, this is localhost.
taskqueue.WithHost("your-redis-host.example.com"),
// Set the Redis username.
taskqueue.WithUsername("redis-username"),
// Set the Redis password.
taskqueue.WithPassword("redis-password"),
// Use your own context object. Useful if operating from within a web request.
taskqueue.WithContext(context.Background()),
// Set a Redis read/write timeout.
taskqueue.WithTimeout(time.Seconds*10),
// Add your own TLS configuration.
taskqueue.WithTLSConfig(&tls.Config{InsecureSkipVerify: true}),
// Don't re-add tasks to the queue that fail when unmarshaled.
taskqueue.WithNoRetry(),
)
# Functions
NewBasic creates a new BasicTaskQueue instance.
NewJSON creates a new JSONTaskQueue instance.
WithContext sets the Redis context object.
WithHost sets the Redis connection host.
WithNoRetry enables or disables task retry, which re-adds the task back to the queue if an error occurs while retrieving it.
WithPassword sets the password to use when authenticating to Redis.
WithTimeout sets the Redis read/write timeout.
WithTLSConfig sets the TLS configuration of the Redis instance.
WithURI sets the Redis URI connection string.
WithUsername sets the username to use when authenticating to Redis.
# Structs
BasicTaskQueue implements a FIFO task queue of string values.
JSONTaskQueue implements a FIFO task queue with any JSON-able value as the value.
No description provided by the author
# Type aliases
No description provided by the author