| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
TaskQueue-Go is a high-performance, distributed task queue library for Go, designed to simplify background job processing. With support for multiple queue backends and job storage backends, along with a pluggable architecture, it provides a scalable and reliable system for decoupling task execution from your main application logic. The decoupled design enables independent scaling and optimization of the queuing system and job storage.
go get github.com/oshankkumar/taskqueue-gopackage main
import (
"context"
"github.com/oshankkumar/taskqueue-go"
"github.com/redis/go-redis/v9"
redisq "github.com/oshankkumar/taskqueue-go/redis"
)
const ns = "taskqueue"
func main() {
rc := redis.NewClient(&redis.Options{Addr: ":6379"})
// Initialize Redis-backed enqueuer
enq := redisq.NewQueue(rc, redisq.WithNamespace(ns))
job := taskqueue.NewJob()
err := job.JSONMarshalPayload(map[string]string{
"to": "user@example.com",
"subject": "Welcome!",
})
if err != nil {
panic(err)
}
err = enq.Enqueue(context.Background(), job, &taskqueue.EnqueueOptions{
QueueName: "email_jobs",
})
if err != nil {
panic(err)
}
}package main
import (
"context"
"fmt"
"os"
"os/signal"
"github.com/oshankkumar/taskqueue-go"
"github.com/redis/go-redis/v9"
redisq "github.com/oshankkumar/taskqueue-go/redis"
)
const ns = "taskqueue"
func main() {
rc := redis.NewClient(&redis.Options{Addr: ":6379"})
worker := taskqueue.NewWorker(&taskqueue.WorkerOptions{
Queue: redisq.NewQueue(rc, redisq.WithNamespace(ns), redisq.WithCompletedJobTTL(time.Hour)),
HeartBeater: redisq.NewHeartBeater(rc, redisq.WithNamespace(ns)),
MetricsBackend: redisq.NewMetricsBackend(rc, redisq.WithNamespace(ns)),
})
worker.RegisterHandler("email_jobs", taskqueue.HandlerFunc(func(ctx context.Context, job *taskqueue.Job) error {
fmt.Printf("Processing job: %+v\n", job)
return nil // Return an error if the job fails
}), taskqueue.WithConcurrency(8))
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer cancel()
worker.Start(ctx)
<-ctx.Done()
worker.Stop()
}To run the TaskQueue Manager locally:
git clone https://github.com/oshankkumar/taskqueue-go.git cd taskqueue-go
cd taskmanager/taskqueue-web yarn install yarn build
go build -o taskqueue-manager ./cmd/taskqueue-manager ./taskqueue-manager -listen=:8050 -namespace=taskqueue-go -redis-heartbeat-addr=redis:6379 -redis-queue-addr=redis:6379 -redis-metrics-backend-addr=redis:6379 --static-web-dir=./taskmanager/taskqueue-web/dist/spa
You can access the dashboard at http://localhost:8050 when running the TaskQueue Manager.
To run the TaskQueue Manager using Docker:
docker run -p 8050:8050 oshank/taskqueue-manager:latest -listen=:8050 -namespace=taskqueue -redis-heartbeat-addr=redis:6379 -redis-metrics-backend-addr=redis:6379 -redis-queue-addr=redis:6379
You can access the dashboard at http://localhost:8050
TaskQueue-Go comes with a nice dashboard for managing and monitoring your queues and jobs. The dashboard provides:
You can implement your own job storage by conforming to the JobStore interface:
type JobStore interface {
CreateOrUpdate(ctx context.Context, job *Job) error
GetJob(ctx context.Context, jobID string) (*Job, error)
DeleteJob(ctx context.Context, jobID string) error
UpdateJobStatus(ctx context.Context, jobID string, status JobStatus) error
}The library leverages a Lua script to ensure atomic dequeuing and visibility timeout management:
This project is licensed under the MIT License. See the LICENSE file for details.
| Back | FazBrowse Home | New Git URL |