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

allows disabling the cron scheduler via settings #62

Closed robacarp closed 3 years ago

robacarp commented 3 years ago

This doesn't completely fix #2 but addresses an inherent problem around the cron scheduler which prevents horizontally scaled mosquito runner architectures.

Problem: When running a cluster of workers each worker will try to enqueue cron-scheduled tasks. This results in N enqueues for N workers, which isn't right if you're trying to enqueue a job to run once an hour.

Solution: A setting is added to the config block which disables the cron scheduler by early exit.

Mosquito.configure do |settings|
  settings.run_cron_scheduler = ENV["MOSQUITO_SCHEDULER"]? || false
end

This allows a primitive but workable solution, as long as the deployment infrastructure will guarantee that a worker with the configuration required will be respawn in the event of a failure. Given the myriad of deployment infrastructure which support this paradigm (Heroku, Kubernetes, ECS, Fargate, etc) I think this is a reasonable solution.