Skip to content

Commit 8499ded

Browse files
committed
Update README with Recurring tasks info
1 parent 134a2f2 commit 8499ded

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

README.md

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,17 @@ It is recommended to set this value less than or equal to the queue database's c
251251
- `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.
252252

253253

254+
### Scheduler polling interval
255+
256+
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`:
257+
258+
```yaml
259+
scheduler:
260+
polling_interval: 5 # seconds
261+
```
262+
263+
This controls how frequently the scheduler wakes up to enqueue due recurring jobs and reload dynamic tasks.
264+
254265
### Queue order and priorities
255266

256267
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`.
@@ -632,7 +643,45 @@ Rails.application.config.after_initialize do # or to_prepare
632643
end
633644
```
634645

635-
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.
646+
### Creating and Deleting Recurring Tasks Dynamically
647+
648+
You can create and delete recurring tasks at runtime, without editing the configuration file. Use the following methods:
649+
650+
#### Creating a recurring task
651+
652+
```ruby
653+
SolidQueue.schedule_recurring_task(
654+
"my_dynamic_task",
655+
command: "puts 'Hello from a dynamic task!'",
656+
schedule: "every 10 minutes"
657+
)
658+
```
659+
660+
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.
661+
662+
#### Deleting a recurring task
663+
664+
```ruby
665+
SolidQueue.delete_recurring_task(task_id)
666+
```
667+
668+
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.
669+
670+
> **Note:** Static recurring tasks (those defined in `config/recurring.yml`) cannot be deleted at runtime. Attempting to do so will raise an error.
671+
672+
#### Example: Creating and deleting a recurring task
673+
674+
```ruby
675+
# Create a new dynamic recurring task
676+
recurring_task = SolidQueue.schedule_recurring_task(
677+
"cleanup_temp_files",
678+
command: "TempFileCleaner.clean!",
679+
schedule: "every day at 2am"
680+
)
681+
682+
# Delete the task later by ID
683+
SolidQueue.delete_recurring_task(recurring_task.id)
684+
```
636685

637686
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.
638687

0 commit comments

Comments
 (0)