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

mosquito is completely broken after 1.0.1 #114

Closed mamantoha closed 1 year ago

mamantoha commented 1 year ago

Mosquito is completely broken after the 1.0.1 release. You can see this straightforward code to reproduce the issue.

require "../src/mosquito"

Mosquito.configure do |settings|
  settings.redis_url = ENV["REDIS_URL"]? || "redis://localhost:6379/3"
end

class PeriodicJob < Mosquito::PeriodicJob
  run_every 10.seconds

  def perform
    puts "Hello world!"
  end
end

Mosquito::Runner.start

Output:

2023-09-30T11:26:24.626816Z NOTICE - mosquito.runner: Mosquito is buzzing...
Unhandled exception in spawn: Channel is closed (Channel::ClosedError)
  from /var/lib/snapd/snap/crystal/1774/share/crystal/src/channel.cr:228:8 in 'send'
  from /var/lib/snapd/snap/crystal/1774/share/crystal/src/log/dispatch.cr:55:7 in 'dispatch'
  from /var/lib/snapd/snap/crystal/1774/share/crystal/src/log/backend.cr:24:5 in 'dispatch'
  from /var/lib/snapd/snap/crystal/1774/share/crystal/src/log/log.cr:36:3 in 'run'
  from src/mosquito/runner.cr:32:9 in '->'
  from /var/lib/snapd/snap/crystal/1774/share/crystal/src/fiber.cr:146:11 in 'run'
  from /var/lib/snapd/snap/crystal/1774/share/crystal/src/fiber.cr:98:34 in '->'
  from ???

No issue before 8dc8629cc3163c60a90f95004d26661634c7e4a0

2023-09-30T11:28:26.994909Z NOTICE - mosquito.runner: Mosquito is buzzing...
Hello world!
2023-09-30T11:28:27.297836Z NOTICE - mosquito.runner: Starting: periodic_job<1696073306996:323> from mosquito::periodic_job
2023-09-30T11:28:27.297926Z NOTICE - mosquito.runner: Success: periodic_job<1696073306996:323> finished and took 3.0µs

Crystal version: 1.9.2 Mosquito Shard version: 1.0.1 (or master)

mamantoha commented 1 year ago

Adding

while Mosquito::Runner.keep_running
  sleep 1
end

after Mosquito::Runner.start fixed the issue.

robacarp commented 1 year ago

@mamantoha thanks for the quick report back! Are you running a dedicated process to trigger Mosquito::Runner.start?

jwoertink commented 1 year ago

Oh, yeah, was just about to post this :joy: Yeah, just deployed the latest this morning and all jobs stopped. Let me know if I can help test anything

wout commented 1 year ago

Same here; I've banged my head against the wall for the past few hours. 😄️ In development there was no output at all from the worker so I figured something changed. Let me know if you need me to test something!

mamantoha commented 1 year ago

Hi @jwoertink @wout. Fixed here https://github.com/mosquito-cr/mosquito/pull/115