项目作者: kavehmz

项目描述 :
A Go queue manager on top of Redis
高级语言: Go
项目地址: git://github.com/kavehmz/queue.git
创建时间: 2015-11-30T10:32:14Z
项目社区:https://github.com/kavehmz/queue

开源协议:MIT License

下载


Queue

Go Lang
GoDoc
Build Status
Coverage Status
Go Report Card
Gitter

A Go library for managing queues on top of Redis.
It is based on a hiring exercise but later I found it useful for myself in a custom task processing project.
I thought it might be useful in general.

Installation

  1. $ go get github.com/kavehmz/queue

Usage

  1. package main
  2. import (
  3. "fmt"
  4. "time"
  5. "github.com/kavehmz/queue"
  6. )
  7. func main() {
  8. var q queue.Queue
  9. q.Urls([]string{"redis://localhost:6379"})
  10. q.AddTask(1, "start")
  11. q.AddTask(2, "start")
  12. q.AddTask(1, "stop")
  13. q.AddTask(2, "stop")
  14. analyzer := func(id int, task chan string, success chan bool) {
  15. for {
  16. select {
  17. case msg := <-task:
  18. fmt.Println(id, msg)
  19. if msg == "stop" {
  20. success <- true
  21. return
  22. }
  23. case <-time.After(2 * time.Second):
  24. fmt.Println("no new events for 2 seconds for ID", id)
  25. success <- false
  26. return
  27. }
  28. }
  29. }
  30. exitOnEmpty := func() bool {
  31. return true
  32. }
  33. q.AnalysePool(1, exitOnEmpty, analyzer)
  34. }

Approach

Focus of this design is mainly horizontal scalability via concurrency, partitioning and fault-detection.