Skip to content

Hunta01/queue

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Queue

Go Lang GoDoc Build Status Coverage Status 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

$ go get github.com/kavehmz/queue

Usage

package main

import (
	"fmt"
	"time"

	"github.com/kavehmz/queue"
)

func main() {
	var q queue.Queue
	q.Urls([]string{"redis://localhost:6379"})
	q.AddTask(1, "start")
	q.AddTask(2, "start")
	q.AddTask(1, "stop")
	q.AddTask(2, "stop")
	analyzer := func(id int, task chan string, success chan bool, next chan bool) {
		for {
			select {
			case msg := <-task:
				fmt.Println(id, msg)
				if msg == "stop" {
					<-next
					success <- true
					return
				}
			case <-time.After(2 * time.Second):
				fmt.Println("no new events for 2 seconds for ID", id)
				<-next
				success <- false
				return
			}
		}
	}
	exitOnEmpty := func() bool {
		return true
	}
	q.AnalysePool(1, exitOnEmpty, analyzer)
}

Approach

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

About

A Go queue manager on top of Redis

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%