Skip to content

Commit c754746

Browse files
committed
Update README with Recurring tasks info
1 parent af8f48c commit c754746

File tree

1 file changed

+52
-2
lines changed

1 file changed

+52
-2
lines changed

README.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,17 @@ It is recommended to set this value less than or equal to the queue database's c
258258
- `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.
259259

260260

261+
### Scheduler polling interval
262+
263+
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`:
264+
265+
```yaml
266+
scheduler:
267+
polling_interval: 5 # seconds
268+
```
269+
270+
This controls how frequently the scheduler wakes up to enqueue due recurring jobs and reload dynamic tasks.
271+
261272
### Queue order and priorities
262273

263274
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`.
@@ -653,8 +664,6 @@ Rails.application.config.after_initialize do # or to_prepare
653664
end
654665
```
655666

656-
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.
657-
658667
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.
659668

660669
**Note**: a single recurring schedule is supported, so you can have multiple schedulers using the same schedule, but not multiple schedulers using different configurations.
@@ -680,6 +689,47 @@ my_periodic_resque_job:
680689

681690
and the job will be enqueued via `perform_later` so it'll run in Resque. However, in this case we won't track any `solid_queue_recurring_execution` record for it and there won't be any guarantees that the job is enqueued only once each time.
682691

692+
693+
### Creating and Deleting Recurring Tasks Dynamically
694+
695+
You can create and delete recurring tasks at runtime, without editing the configuration file. Use the following methods:
696+
697+
#### Creating a recurring task
698+
699+
```ruby
700+
SolidQueue.schedule_recurring_task(
701+
"my_dynamic_task",
702+
command: "puts 'Hello from a dynamic task!'",
703+
schedule: "every 10 minutes"
704+
)
705+
```
706+
707+
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.
708+
709+
#### Deleting a recurring task
710+
711+
```ruby
712+
SolidQueue.delete_recurring_task(task_id)
713+
```
714+
715+
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.
716+
717+
> **Note:** Static recurring tasks (those defined in `config/recurring.yml`) cannot be deleted at runtime. Attempting to do so will raise an error.
718+
719+
#### Example: Creating and deleting a recurring task
720+
721+
```ruby
722+
# Create a new dynamic recurring task
723+
recurring_task = SolidQueue.schedule_recurring_task(
724+
"cleanup_temp_files",
725+
command: "TempFileCleaner.clean!",
726+
schedule: "every day at 2am"
727+
)
728+
729+
# Delete the task later by ID
730+
SolidQueue.delete_recurring_task(recurring_task.id)
731+
```
732+
683733
## Inspiration
684734

685735
Solid Queue has been inspired by [resque](https://github.com/resque/resque) and [GoodJob](https://github.com/bensheldon/good_job). We recommend checking out these projects as they're great examples from which we've learnt a lot.

0 commit comments

Comments
 (0)