Dispatch - in memory asynchronous job processing
Switch branches/tags
Nothing to show
Clone or download
Latest commit 7d1eab6 Oct 12, 2018
Permalink
Failed to load latest commit information.
spec Remove size for now Dec 21, 2016
src Require dispatch/* Oct 12, 2018
.travis.yml Add travis.yml Dec 7, 2016
README.md Add queue alias, update example, abstract def perform Dec 16, 2016
example.cr Rerun formatter Oct 8, 2018
shard.yml Update shard.yml Dec 10, 2016

README.md

Dispatch Build Status

In-memory job queuing

# 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 # => <Dispatch::Configuration:0x1042dafb0 @num_workers=5, @queue_size=10>
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"