Skip to content

Commit 6a54d5e

Browse files
committed
Add Schedule Sidekiq Jobs Out Into The Future as a rails til
1 parent 42dd8b7 commit 6a54d5e

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ and pairing with smart people at Hashrocket.
99

1010
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
1111

12-
_907 TILs and counting..._
12+
_908 TILs and counting..._
1313

1414
---
1515

@@ -570,6 +570,7 @@ _907 TILs and counting..._
570570
- [Rescue From](rails/rescue-from.md)
571571
- [Retrieve An Object If It Exists](rails/retrieve-an-object-if-it-exists.md)
572572
- [Rounding Numbers With Precision](rails/rounding-numbers-with-precision.md)
573+
- [Schedule Sidekiq Jobs Out Into The Future](rails/schedule-sidekiq-jobs-out-into-the-future.md)
573574
- [Secure Passwords With Rails And Bcrypt](rails/secure-passwords-with-rails-and-bcrypt.md)
574575
- [Select A Select By Selector](rails/select-a-select-by-selector.md)
575576
- [Select Value For SQL Counts](rails/select-value-for-sql-counts.md)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Schedule Sidekiq Jobs Out Into The Future
2+
3+
The most common way to schedule a [Sidekiq](https://github.com/mperham/sidekiq)
4+
job is with the `perform_async` method. That will queue up your job so that it
5+
is worked as soon as possible. That may not also be desired. Sometimes you
6+
want a bit more say in when jobs are run.
7+
8+
The `perform_in` and `perform_at` methods can help with scheduling jobs out
9+
into the future.
10+
11+
With `perform_in` we can say how much time from now would be the soonest that
12+
we'd like the job performed.
13+
14+
```ruby
15+
MyWorker.perform_in(10.minutes, arg1, arg2)
16+
```
17+
18+
We can do the same thing with `perform_at`.
19+
20+
```ruby
21+
MyWorker.perform_at(10.minutes.from_now, arg1, arg2)
22+
```
23+
24+
Or we can schedule something out for a specific point in time in the future.
25+
26+
```ruby
27+
MyWorker.perform_at(Date.today.end_of_week, arg1, arg2)
28+
```
29+
30+
[source](https://github.com/mperham/sidekiq/wiki/Scheduled-Jobs)

0 commit comments

Comments
 (0)