diff --git a/README.md b/README.md index 71eb22d..98daad0 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ and pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_907 TILs and counting..._ +_908 TILs and counting..._ --- @@ -570,6 +570,7 @@ _907 TILs and counting..._ - [Rescue From](rails/rescue-from.md) - [Retrieve An Object If It Exists](rails/retrieve-an-object-if-it-exists.md) - [Rounding Numbers With Precision](rails/rounding-numbers-with-precision.md) +- [Schedule Sidekiq Jobs Out Into The Future](rails/schedule-sidekiq-jobs-out-into-the-future.md) - [Secure Passwords With Rails And Bcrypt](rails/secure-passwords-with-rails-and-bcrypt.md) - [Select A Select By Selector](rails/select-a-select-by-selector.md) - [Select Value For SQL Counts](rails/select-value-for-sql-counts.md) diff --git a/rails/schedule-sidekiq-jobs-out-into-the-future.md b/rails/schedule-sidekiq-jobs-out-into-the-future.md new file mode 100644 index 0000000..8f70928 --- /dev/null +++ b/rails/schedule-sidekiq-jobs-out-into-the-future.md @@ -0,0 +1,30 @@ +# Schedule Sidekiq Jobs Out Into The Future + +The most common way to schedule a [Sidekiq](https://github.com/mperham/sidekiq) +job is with the `perform_async` method. That will queue up your job so that it +is worked as soon as possible. That may not also be desired. Sometimes you +want a bit more say in when jobs are run. + +The `perform_in` and `perform_at` methods can help with scheduling jobs out +into the future. + +With `perform_in` we can say how much time from now would be the soonest that +we'd like the job performed. + +```ruby +MyWorker.perform_in(10.minutes, arg1, arg2) +``` + +We can do the same thing with `perform_at`. + +```ruby +MyWorker.perform_at(10.minutes.from_now, arg1, arg2) +``` + +Or we can schedule something out for a specific point in time in the future. + +```ruby +MyWorker.perform_at(Date.today.end_of_week, arg1, arg2) +``` + +[source](https://github.com/mperham/sidekiq/wiki/Scheduled-Jobs)