mosquito-cr / mosquito

A background task runner for crystal applications supporting periodic (CRON) and manually queued jobs
MIT License
227 stars 24 forks source link

API - executors now publish events #154

Closed robacarp closed 1 week ago

robacarp commented 1 week ago

This allows a simple real time approach to monitoring a mosquito cluster:

ic(1.13.1):pry> c = Mosquito::Api.event_receiver
 => #<Channel(Mosquito::Backend::BroadcastMessage):0x146c30c80>
ic(1.13.1):pry> c.receive
 => Mosquito::Backend::BroadcastMessage(@channel="mosquito:executor:4385634608", @message="{\"event\":\"job-started\",\"job_run\":\"1731083800881:387\",\"from_queue\":\"demo_queue\"}")

In this example, after executing c.receive, I ran make demo in another terminal tab. There's still some reasonable work to be done to queue up messages when the receiver isn't yet listening, but that'll wait until I have a real use case in my hands.