Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bmulvihill/dispatch

Dispatch - in memory asynchronous job processing
https://github.com/bmulvihill/dispatch

concurrency crystal job-queue

Last synced: about 1 month ago
JSON representation

Dispatch - in memory asynchronous job processing

Awesome Lists containing this project

README

        

# Dispatch [![Build Status](https://travis-ci.org/bmulvihill/dispatch.svg?branch=master)](https://travis-ci.org/bmulvihill/dispatch)

### In-memory job queuing
```crystal
# example.cr
require "./src/dispatch"

Dispatch.configure do |config|
config.num_workers = 5
config.queue_size = 10
config.logger = Logger.new(IO::Memory.new)
end

class FakeJob
include Dispatchable

def perform(name)
p "#{Time.now}: Hello, #{name}"
end
end

class ErrorJob
include Dispatchable

def perform
raise "Hello!"
end
end

Dispatch.config # =>
FakeJob.dispatch("Bob")
FakeJob.dispatch("Emily")
FakeJob.dispatch_in(5.seconds, "Billy")
FakeJob.dispatch("Maddy")

ErrorJob.dispatch

Dispatch.successes # => 0

sleep 6

Dispatch.successes # => 4
Dispatch.failures # => 1
```

Output:
```
"2016-12-13 14:23:53 -0500: Hello, Bob"
"2016-12-13 14:23:53 -0500: Hello, Emily"
"2016-12-13 14:23:53 -0500: Hello, Maddy"
"2016-12-13 14:23:58 -0500: Hello, Billy"
```