• Stars
    star
    3
  • Rank 3,848,222 (Top 78 %)
  • Language
    Crystal
  • License
    MIT License
  • Created almost 8 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Crystal client for the Disque queueing system.

disque.cr

Crystal client for Disque, an in-memory, distributed job queue.

Installation

Add this to your application's shard.yml:

dependencies:
  disque:
    github: foca/disque
    branch: master

Usage

Create a new Disque client by passing a list of nodes:

client = Disque.new(["127.0.0.1:7711", "127.0.0.1:7712", "127.0.0.1:7713"])

Alternatively, you can pass a single string with comma-separated nodes:

client = Disque.new("127.0.0.1:7711,127.0.0.1:7712,127.0.0.1:7713")

Using a single string is useful if you are receiving the list of nodes from an environment variable.

If the nodes are password protected, you can pass the AUTH string:

client = Disque.new("127.0.0.1:7711", auth: "e727d1464a...")

The client keeps track of which nodes are providing more jobs, and after a given number operations it tries to connect to the preferred node. The number of operations for each cycle defaults to 1000, but it can be configured:

client = Disque.new("127.0.0.1:7711", cycle: 20000)

Now you can add jobs:

client.push("foo", "bar", 100)

It will push the job "bar" to the queue "foo" with a timeout of 100 ms, and return the id of the job if it was received and replicated in time.

Disque's ADDJOB signature is as follows:

ADDJOB queue_name job <ms-timeout>
  [REPLICATE <count>]
  [DELAY <sec>]
  [RETRY <sec>]
  [TTL <sec>]
  [MAXLEN <count>]
  [ASYNC]

You can pass any optional arguments as a hash, for example:

disque.push("foo", "myjob", 1000, ttl: 1, async: true)

Note that async is a special case because it's just a flag. That's why true must be passed as its value.

Then, your workers will do something like this:

loop do
  client.fetch(from: ["foo"]) do |job|
    # Do something with `job`
  end
end

The fetch command receives an array of queues, and optionally a timeout (in milliseconds) and the count of jobs to retrieve:

client.fetch(from: ["bar", "baz"], count: 10, timeout: 2000)

Example

Run in a terminal:

DISQUE_NODES=127.0.0.1:7711 crystal run example/worker.cr

And in another:

DISQUE_NODES=127.0.0.1:7711 crystal run example/timer.cr

Adjust DISQUE_NODES to your local-running instances of Disque.

License

This is released under the MIT license. See LICENSE for details. The code was mostly adapted from soveran's disque-rb project.

More Repositories

1

sinatra-content-for

Sinatra extension to use a `content_for` helper similar to Rails' โ€“ Don't use it, use Sinatra::Contrib instead.
Ruby
65
star
2

sinatra-mailer

Send emails from Sinatra in a very simple way
Ruby
58
star
3

undress

Easily convert HTML into Textile, Markdown, LaTeX, YAML, or whatever you want to =)
Ruby
56
star
4

sinatra-tmbundle

Use https://github.com/blinklys/sinatra-tmbundle, it's maintained :)
51
star
5

sinatra-ditties

A series of plugins and useful helpers for the Sinatra web framework
Ruby
42
star
6

granola

Simple JSON serializers (Cereal-izers. GET IT?)
Ruby
39
star
7

beacon

Simple observers for your code
Ruby
30
star
8

utility_scripts

Some utility scripts (the stuff I keep in ~/bin)
27
star
9

ensure

Tiny shell scripts to install things in your mac.
Shell
27
star
10

ninja

Run tasks in the background
Ruby
23
star
11

storyteller

Minimalist user stories for test/unit
Ruby
22
star
12

protest

E PUR SI MUOVE โ€” Now protest lives at http://github.com/matflores/protest :)
Ruby
21
star
13

mpp

The mini pre processor parses files and resolves C-style #include and #define macros
Crystal
20
star
14

node-marshmallow

A campfire bot in node.js
JavaScript
20
star
15

scrooge

This library is pretty much useless now, ActiveRecord supports this out of the box
Ruby
16
star
16

writ

Minimal command pattern implementation on top of Scrivener
Ruby
16
star
17

mustache-on-rails-example

A sample rails app to get mustache working on it
Ruby
14
star
18

integrity-email

Email notifier for the Integrity continuous integration server
Ruby
14
star
19

flickr-downloader

Sinatra app that lists your flickr photosets and lets you download a zipfile with the contents of each one.
Ruby
14
star
20

migrake

Rake tasks that act as ActiveRecord::Migrations, useful for running after a deploy
Ruby
13
star
21

Transporter

Deliver packages in multiple ways simultaneously (email, jabber, campfire, irc, etc.)
Ruby
10
star
22

dtb

DataTable Builder provides simple building blocks to build complex filterable queries and turn them into easy to render datatables using Rails.
Ruby
10
star
23

bloodhound

Easy conversion from "foo:bar baz:1" to { "foo" => "bar", "baz" => 1 }
Ruby
9
star
24

sinatra-url

URL mapper for the Sinatra framework
Ruby
9
star
25

kaleidoscope

Easy and clean model factories for active record, without touching the internals
Ruby
9
star
26

hal

Simple authorization framework for ruby
Ruby
7
star
27

gerbil-rails

Test your javascript in rails within the asset pipeline, with Gerbil!
JavaScript
7
star
28

moody

Simple and straightforward implementation of the State Pattern in ruby
Ruby
6
star
29

expectacular

Expectations for your Test::Unit tests (DSL to use instead of "assert" and friends)
Ruby
5
star
30

integrity-website

what runs http://integrityapp.com
JavaScript
5
star
31

migajas

Tiny breadcrumbs for your Rack apps.
Ruby
5
star
32

flagpole

Store multiple flags in an Integer field by using a bitmap
Ruby
5
star
33

bob

Bob the Builder will build your codes
Ruby
5
star
34

stateful.js

Minimalistic implementation of the State pattern in JavaScript
JavaScript
5
star
35

integrity-rewrite

*not meant for public use*
Ruby
5
star
36

foca.github.io

My personal website
CSS
4
star
37

travel

4
star
38

sinatra-ghetto_i18n

Oversimplified translations for your Sinatra application
Ruby
4
star
39

sequel_on_connect

Run callbacks after connecting to a database using the Sequel database toolkit
Ruby
4
star
40

granola-cache

Cache the output of your Granola serializers.
Ruby
4
star
41

love-nest

Simple nested contexts for your tests
Ruby
4
star
42

genlock

Generate `Gemfile.lock` files from your `.gems` file.
Ruby
4
star
43

magnetizer

Tiny menu bar app to automatically add torrents to a remote transmission server
Swift
3
star
44

protest-website

The website for Protest, the simple test framework
2
star
45

granola-rails

Rails wrapper for Granola
Ruby
2
star
46

granola-schema

JSON Schema support for Granola serialisers
Ruby
2
star
47

asset_manifest

Utilities for managing static assets in ruby apps.
Ruby
2
star
48

vault

A lightweight Object Document Mapper based on ActiveModel
Ruby
2
star
49

sinatra-example-blog

Code used in my Locos x Rails presentation on the Sinatra web framework
2
star
50

transporter-campfire

Deliver messages to your Campfire room using Transporter
Ruby
2
star
51

availabledomains

Tiny website to check availability of multiple domains at once using shell glob expressions
Ruby
1
star
52

gns-website

Website for The Gaming Night Society
Ruby
1
star
53

Test-Repository

blah
Ruby
1
star
54

puppet-inconsolata

Get the Inconsolata font via Boxen
Puppet
1
star
55

dl-tools

Scripts to download movies/shows/subtitles and sort them into directories
Ruby
1
star
56

README

My Blog
Ruby
1
star
57

blank_slate_rails_app

A rails app with the minimum configuration and default settings so I can start hacking right away
Ruby
1
star
58

alasocho-geoip

IP geolocation service for alasocho.com
Ruby
1
star
59

migrake-sql_store

An extension for migrake that stores the run tasks in a SQL table instead of the filesystem, useful for heroku and similar hosts
Ruby
1
star
60

aoc

Crystal
1
star