Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/bmulvihill/dispatch
- Owner: bmulvihill
- Created: 2016-11-29T02:01:39.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-01-09T16:44:21.000Z (11 months ago)
- Last Synced: 2024-08-01T17:36:29.594Z (4 months ago)
- Topics: concurrency, crystal, job-queue
- Language: Crystal
- Homepage:
- Size: 20.5 KB
- Stars: 32
- Watchers: 4
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-crystal - dispatch - In memory asynchronous job processing (Queues and Messaging)
- awesome-crystal - dispatch - In memory asynchronous job processing (Queues and Messaging)
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)
endclass FakeJob
include Dispatchabledef perform(name)
p "#{Time.now}: Hello, #{name}"
end
endclass ErrorJob
include Dispatchabledef perform
raise "Hello!"
end
endDispatch.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"
```