Dynamic recurring-task reschedule is not detected when the same key is recreated before the next scheduler poll
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 55/100
Línea de trabajo
Start with lib/solid_queue/scheduler/recurring_schedule.rb and trace how Scheduler invokes reschedule_dynamic_tasks from lib/solid_queue/scheduler.rb. Reproduce with dynamic tasks enabled and a short polling interval, then verify that replacing a task with the same key causes the active schedule to use the new definition without restarting the scheduler.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
The documented way to update a dynamic recurring task is to unschedule it and then schedule it again with the same key and updated options:
SolidQueue.unschedule_recurring_task("my_dynamic_task")
SolidQueue.schedule_recurring_task(
"my_dynamic_task",
class: "MyJob",
schedule: "every 10 minutes"
)
However, if the deletion and recreation both happen before the scheduler's next dynamic-task poll, the scheduler does not pick up the new schedule. It continues using the old in-memory task definition.
This also occurs if both operations are wrapped in a single database transaction, because the scheduler can never observe the row as absent.
Environment
- Solid Queue: 1.7.0
- Rails: 8.1
- Ruby: 3.3.11
- Database: mysql2 0.5.1
- Scheduler mode: default
config/queue.yml:
development:
dispatchers:
- polling_interval: 5 # seconds
batch_size: 500
workers:
- queues: "*"
threads: 1
processes: 1
polling_interval: 5 # seconds
scheduler:
dynamic_tasks_enabled: true
polling_interval: 5 # seconds
Reproduction
Start a scheduler with dynamic tasks enabled and a short polling interval.
Schedule a task with a schedule that runs frequently:
SolidQueue.schedule_recurring_task(
"dynamic_task",
class: "ProbeJob",
schedule: "every second"
)
After the scheduler has picked up the task, immediately replace it using the documented API:
SolidQueue.unschedule_recurring_task("dynamic_task")
SolidQueue.schedule_recurring_task(
"dynamic_task",
class: "ProbeJob",
schedule: "every minute"
)
Ensure both calls complete before the next polling_interval elapses.
Actual behavior
The scheduler continues to run the original every second schedule. The replacement task record is present in solid_queue_recurring_tasks with schedule: "every minute", but its updated schedule is not used until the scheduler restarts.
Expected behavior
Using the documented unschedule-and-reschedule sequence should replace the active dynamic task definition, even when both database operations occur between scheduler polls.
Alternatively, if this timing constraint is intentional, the documentation should explicitly require waiting until the scheduler observes the deletion before recreating the task with the same key.
Why this happens
Scheduler::RecurringSchedule#reschedule_dynamic_tasks reloads dynamic tasks, then performs only key-based reconciliation:
def schedule_created_dynamic_tasks
RecurringTask.dynamic.where.not(key: scheduled_tasks.keys).each do |task|
schedule_task(task)
end
end
def unschedule_deleted_dynamic_tasks
(scheduled_tasks.keys - RecurringTask.pluck(:key)).each do |key|
scheduled_tasks[key].cancel
scheduled_tasks.delete(key)
end
end
When the row is deleted and recreated with the same key between polls:
scheduled_tasksstill contains"dynamic_task"from the old definition.- The database also contains
"dynamic_task"from the new definition. where.not(key: scheduled_tasks.keys)returns no row.- The subtraction against
RecurringTask.pluck(:key)also returns no key.
As a result, neither method schedules the replacement nor cancels the old in-memory Concurrent::ScheduledTask.
Relevant source:
lib/solid_queue/scheduler/recurring_schedule.rb
https://github.com/rails/solid_queue/blob/main/lib/solid_queue/scheduler/recurring_schedule.rblib/solid_queue/scheduler.rb
https://github.com/rails/solid_queue/blob/main/lib/solid_queue/scheduler.rb
The README explicitly recommends this sequence under “Scheduling and unscheduling recurring tasks dynamically”:
https://github.com/rails/solid_queue#scheduling-and-unscheduling-recurring-tasks-dynamically
Possible fix
Reconcile changed dynamic task definitions as well as created/deleted keys. For example, retain the task definition or a stable fingerprint/version/updated_at alongside each scheduled task and cancel/recreate the scheduled task when its persisted attributes change.
- Lenguaje dominante
- Ruby
- Estrellas
- 2.5k
- Forks
- 255
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Incluye un Dockerfile o un archivo de Docker Compose
- Sin plantilla de pull request
- Sin guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rails/solid_queue
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 42/100
rails/solid_queue#808 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
rails/solid_queue#806 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
rails/solid_queue#805 ·
-
limits_concurrency on_conflict: :discard looking only into running jobs and not blocked jobsAbierto
Dificultad 3/5 1-2 días Aptitud para principiantes 52/100
rails/solid_queue#804 · 1 comentario ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
rails/solid_queue#802 ·
Todos los issues de rails/solid_queue
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
rubys/roundhouse#444 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
sclorg/s2i-ruby-container#656 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
request
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
endoflife-date/endoflife.date#11277 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
yegor256/rubocop-elegant#92 ·