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

implements before/after enqueue hooks on QueuedJob #146

Closed robacarp closed 1 month ago

robacarp commented 1 month ago

fixes #130

You can now use the before_enqueue macro to preempt a job from being enqueued -- for example to prevent re-queueing a job if it's already been queued. Or if Jobs should only be run on a certain day of the week, like this:

class SomeJob < Mosquito::QueuedJob
  param only_run_on : String

  before_enqueue do
    # true if the job should be enqueued, false if not
    job.config["only_run_on"] == Time.utc.day_of_week
  end

  after_enqueue do
    # `job.config["only_run_on"]` exists here too
  end
end