Update your shard.yml to include mosquito, and run shards install
:
targets:
app:
main: src/my_app.cr
+ worker:
+ main: src/worker.cr
dependencies:
+ mosquito:
+ github: mosquito-cr/mosquito
# config/worker.cr
require "mosquito"
Mosquito.configure do |settings|
settings.redis_url = ENV["REDIS_URL"]
end
# src/worker.cr
require "../config/worker.cr"
Mosquito::Runner.start
# src/jobs/puts_job.cr
class PutsJob < Mosquito::QueuedJob
param message : String
def perform
puts message
end
end
PutsJob.new(message: "hello world").enqueue
crystal run src/worker.cr
> crystal run src/worker.cr
2017-11-06 17:07:29 - Mosquito is buzzing...
2017-11-06 17:07:51 - Running task puts_job<...> from puts_job
2017-11-06 17:07:51 - [PutsJob] hello world
2017-11-06 17:07:51 - task puts_job<...> succeeded, took 0.0 seconds