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

[Feature request] add delayed jobs #72

Closed watzon closed 2 years ago

watzon commented 2 years ago

It would be nice if it were possible to queue a delayed job. Maybe with the following API:

# src/<somewher>/<somefile>.cr
PutsJob.new(message: "ohai background job").enqueue(in: 30.seconds)
# and
PutsJob.new(message: "ohai background job").enqueue(at: Time.utc(2022, 1, 1, 0, 0,0))

in the first case it would save the job in redis with the timestamp Time.utc + 30.seconds and in the second it would save it with the timestamp of the new year, then when Time.utc is greater than or equal to that timestamp it would add the job to the queue.

Sidekiq has something like this already, but I like Mosquito more and would like to see something like that here.

watzon commented 2 years ago

Nvm I found it in the code https://github.com/mosquito-cr/mosquito/blob/master/src/mosquito/queued_job.cr#L112

I'll see about getting it added to the Wiki. I wasn't able to find anything there.

robacarp commented 2 years ago

@watzon thank you for pointing out the documentation gap around this feature. I've added a page to the wiki: https://github.com/mosquito-cr/mosquito/wiki/Scheduling-Queued-Jobs-for-later