Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Commit

Permalink
Merge pull request #5 from goware/config_defaults
Browse files Browse the repository at this point in the history
Add config defaults to README
  • Loading branch information
VojtechVitek committed May 6, 2015
2 parents 48518a7 + 97f1467 commit 56664cb
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- **Persistent** - Jobs can be either in-memory or persisted on disk<sup>[[1]](https://github.com/antirez/disque#disque-and-disk-persistence)</sup>.
- **Distributed** - Disque pool. Multiple producers, multiple consumers.
- **Job Priority Queue** - Multiple queues. Consumers `Get()` from higher priority queues first.
- **Fault tolerant** - Jobs must be replicated to N nodes before `Add()` returns. Jobs must be `ACK()`ed after `Get()` or they'll be re-queued automatically within a specified `RetryAfter` timeout.
- **Fault tolerant** - Jobs must be replicated to N nodes before `Add()` returns. Consumer must `Ack()` the job within a specified `RetryAfter` timeout or the job will be re-queued automatically.

[![GoDoc](https://godoc.org/github.com/goware/disque?status.png)](https://godoc.org/github.com/goware/disque)
[![Travis](https://travis-ci.org/goware/disque.svg?branch=master)](https://travis-ci.org/goware/disque)
Expand Down Expand Up @@ -44,7 +44,7 @@ func main() {

for {
// Get job from highest priority queue possible. Blocks by default.
job, _ := jobs.Get("urgent", "high", "low") // Left-right priority.
job, _ := jobs.Get("urgent", "high", "low") // Left-to-right priority.

// Do some hard work with the job data.
if err := Process(job.Data); err != nil {
Expand All @@ -58,18 +58,29 @@ func main() {
}
```

## Config (Timeout, Replicate, Delay, Retry, TTL, MaxLen)
## Default configuration

| Config option | Default value | Description |
| ------------- |:-------------:| ------------ |
| Timeout | 0 | Blocks on each operation until it returns. |
| Replicate | 0 | Job doesn't need to be replicated before Add() returns. |
| Delay | 0 | Job is added immediately. |
| RetryAfter | 0 | Job is not re-queued automatically. |
| TTL | 0 | Job lives until it's ACKed. |
| MaxLen | 0 | Unlimited queue. |

## Custom configuration

```go
jobs, _ := disque.Connect("127.0.0.1:7711")

config := disque.Config{
Timeout: time.Second, // Each operation will fail after 1s. It blocks by default.
Replicate: 2, // Add(): Replicate job to at least two nodes before return.
Delay: time.Hour, // Add(): Schedule the job - enqueue after one hour.
RetryAfter: time.Minute, // Add(): Re-queue job after 1min (time between Get() and Ack()).
TTL: 24 * time.Hour, // Add(): Remove the job from queue after one day.
MaxLen: 1000, // Add(): Fail if there are more than 1000 jobs in the queue.
Timeout: time.Second, // Every operation timeouts after 1s.
Replicate: 2, // Replicates job to 2+ nodes before Add() returns.
Delay: time.Hour, // Schedules the job (enqueues after 1h).
RetryAfter: time.Minute, // Re-queues the job after 1min of not being ACKed.
TTL: 24 * time.Hour, // Removes the job from the queue after one day.
MaxLen: 1000, // Fails if there are 1000+ jobs in the queue.
}

// Apply globally.
Expand All @@ -81,7 +92,7 @@ jobs.With(config).Add(data, "queue")
// Apply single option to a single operation.
jobs.Timeout(time.Second).Get("queue", "queue2")
jobs.MaxLen(1000).RetryAfter(time.Minute).Add(data, "queue")
jobs.Timeout(time.Second).Add(data, "queue")
jobs.TTL(24 * time.Hour).Add(data, "queue")
```

## License
Expand Down

0 comments on commit 56664cb

Please sign in to comment.