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

Can't use months with PeriodicJob #65

Closed jwoertink closed 2 years ago

jwoertink commented 3 years ago
class AccountExpirationWorker < Mosquito::PeriodicJob
  run_every 1.month

  def perform
  end
end
no overload matches 'Mosquito::Base.register_job_interval' with types NotifyCardsExpiringWorker.class, Time::MonthSpan

This one might be a little tricky since months change length. For now, using 30.days works.

Crystal 1.1.1 Mosquito 0.11.0

robacarp commented 3 years ago

MonthSpan is a different thing from Time::Span, eh. Crystals date math might be able to rescue this situation by changing the way the math is calculated. As is, simply adding MonthSpan will fail:

(Here 45.days.ago is the "last run time" in this code and 1.month is the interval)

p (Time.utc - 45.days.ago) > 1.month
=> Error: no overload matches 'Time::Span#>' with type Time::MonthSpan

Buuuuuuuut

p (45.days.ago + 1.month) <= Time.utc
=> true

There might be a little fuzz around the math but the way crystal is incrementing the month number seems like it'll usually work well enough.