Skip to content

Commit 214a7f6

Browse files
committed
Update README with Recurring tasks info
1 parent 9c3abbd commit 214a7f6

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`.
@@ -678,8 +689,6 @@ Rails.application.config.after_initialize do # or to_prepare
678689
end
679690
```
680691

681-
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.
682-
683692
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.
684693

685694
**Note**: a single recurring schedule is supported, so you can have multiple schedulers using the same schedule, but not multiple schedulers using different configurations.
@@ -705,6 +714,47 @@ my_periodic_resque_job:
705714

706715
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.
707716

717+
718+
### Creating and Deleting Recurring Tasks Dynamically
719+
720+
You can create and delete recurring tasks at runtime, without editing the configuration file. Use the following methods:
721+
722+
#### Creating a recurring task
723+
724+
```ruby
725+
SolidQueue.schedule_recurring_task(
726+
"my_dynamic_task",
727+
command: "puts 'Hello from a dynamic task!'",
728+
schedule: "every 10 minutes"
729+
)
730+
```
731+
732+
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.
733+
734+
#### Deleting a recurring task
735+
736+
```ruby
737+
SolidQueue.delete_recurring_task(task_id)
738+
```
739+
740+
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.
741+
742+
> **Note:** Static recurring tasks (those defined in `config/recurring.yml`) cannot be deleted at runtime. Attempting to do so will raise an error.
743+
744+
#### Example: Creating and deleting a recurring task
745+
746+
```ruby
747+
# Create a new dynamic recurring task
748+
recurring_task = SolidQueue.schedule_recurring_task(
749+
"cleanup_temp_files",
750+
command: "TempFileCleaner.clean!",
751+
schedule: "every day at 2am"
752+
)
753+
754+
# Delete the task later by ID
755+
SolidQueue.delete_recurring_task(recurring_task.id)
756+
```
757+
708758
## Inspiration
709759

710760
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)