You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+50-1Lines changed: 50 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -250,6 +250,17 @@ It is recommended to set this value less than or equal to the queue database's c
250
250
- `concurrency_maintenance`: whether the dispatcher will perform the concurrency maintenance work. This is `true` by default, and it's useful if you don't use any [concurrency controls](#concurrency-controls) and want to disable it or if you run multiple dispatchers and want some of them to just dispatch jobs without doing anything else.
251
251
252
252
253
+
### Scheduler polling interval
254
+
255
+
The scheduler process checks for due recurring tasks and reloads dynamic tasks at a configurable interval. You can set this interval using the `polling_interval` key under the `scheduler` section in your `config/queue.yml`:
256
+
257
+
```yaml
258
+
scheduler:
259
+
polling_interval: 5 # seconds
260
+
```
261
+
262
+
This controls how frequently the scheduler wakes up to enqueue due recurring jobs and reload dynamic tasks.
263
+
253
264
### Queue order and priorities
254
265
255
266
As mentioned above, if you specify a list of queues for a worker, these will be polled in the order given, such as for the list `real_time,background`, no jobs will be taken from `background` unless there aren't any more jobs waiting in `real_time`.
@@ -607,7 +618,45 @@ Rails.application.config.after_initialize do # or to_prepare
607
618
end
608
619
```
609
620
610
-
You can also dynamically add or remove recurring tasks by creating or deleting SolidQueue::RecurringTask records. It works the same way as with static tasks, except you must set the static field to false. Changes won’t be picked up immediately — they take effect after about a one-minute delay.
621
+
### Creating and Deleting Recurring Tasks Dynamically
622
+
623
+
You can create and delete recurring tasks at runtime, without editing the configuration file. Use the following methods:
624
+
625
+
#### Creating a recurring task
626
+
627
+
```ruby
628
+
SolidQueue.schedule_recurring_task(
629
+
"my_dynamic_task",
630
+
command: "puts 'Hello from a dynamic task!'",
631
+
schedule: "every 10 minutes"
632
+
)
633
+
```
634
+
635
+
This will create a dynamic recurring task with the given key, command, and schedule. You can also use the `class` and `args` options as in the configuration file.
636
+
637
+
#### Deleting a recurring task
638
+
639
+
```ruby
640
+
SolidQueue.delete_recurring_task(task_id)
641
+
```
642
+
643
+
This will delete a dynamically scheduled recurring task by its ID. If you attempt to delete a static (configuration-defined) recurring task, an error will be raised.
644
+
645
+
> **Note:** Static recurring tasks (those defined in `config/recurring.yml`) cannot be deleted at runtime. Attempting to do so will raise an error.
646
+
647
+
#### Example: Creating and deleting a recurring task
It's possible to run multiple schedulers with the same `recurring_tasks` configuration, for example, if you have multiple servers for redundancy, and you run the `scheduler` in more than one of them. To avoid enqueuing duplicate tasks at the same time, an entry in a new `solid_queue_recurring_executions` table is created in the same transaction as the job is enqueued. This table has a unique index on `task_key` and `run_at`, ensuring only one entry per task per time will be created. This only works if you have `preserve_finished_jobs` set to `true` (the default), and the guarantee applies as long as you keep the jobs around.
0 commit comments