solid_queue icon indicating copy to clipboard operation
solid_queue copied to clipboard

Anchors do not work in recurring jobs yaml file

Open rbarrera87 opened this issue 7 months ago • 2 comments

I am trying to setup my recurring jobs and I tried use anchors to do something like this:

production:
  the_recurring_job: &the_recurring_job
    queue: low
    class: TheRecurringJob
    schedule: "0 */2 * * *" # every 2h
    args:
      - arg1: "Some arg"
development:
  the_recurring_job: *the_recurring_job

I tried with:

production:
  the_recurring_job: &the_recurring_job
    queue: low
    class: TheRecurringJob
    schedule: "0 */2 * * *" # every 2h
    args:
      - arg1: "Some arg"
development:
  the_recurring_job: 
    <<: *the_recurring_job

But it didn't work either. When parsing this YAML to JSON I don't get any syntax error whatsoever, this is the output in JSON:

{
  "development": {
    "the_recurring_job": {
      "queue": "low", 
      "args": [
        {
          "arg1": "Some arg"
        }
      ], 
      "class": "TheRecurringJob", 
      "schedule": "0 */2 * * *"
    }
  }, 
  "production": {
    "the_recurring_job": {
      "queue": "low", 
      "args": [
        {
          "arg1": "Some arg"
        }
      ], 
      "class": "TheRecurringJob", 
      "schedule": "0 */2 * * *"
    }
  }
}

The error I am getting is this:

/usr/local/bundle/gems/psych-5.1.2/lib/psych/visitors/to_ruby.rb:432:in `visit_Psych_Nodes_Alias': Alias parsing was not enabled. To enable it, pass `aliases: true` to `Psych::load` or `Psych::safe_load`. (Psych::AliasesNotEnabled)

However this works when I do the same but without anchors:

production:
  the_recurring_job:
    queue: low
    class: TheRecurringJob
    schedule: "0 */2 * * *" # every 2h
    args:
      - arg1: "Some arg"
development:
  the_recurring_job:
    queue: low
    class: TheRecurringJob
    schedule: "0 */2 * * *" # every 2h
    args:
      - arg1: "Some arg"

Am I missing something or doing something wrong? Rails version: Rails 7.1.5.1 Ruby version: ruby 3.3.8 (2025-04-09 revision b200bad6cd) [aarch64-linux] Solid Queue version: solid_queue (1.1.4)

Thank you!

rbarrera87 avatar Apr 25 '25 19:04 rbarrera87

Try

production:
  the_recurring_job: &the_recurring_job
    queue: low
    class: TheRecurringJob
    schedule: "0 */2 * * *" # every 2h
    args:
      - arg1: "Some arg"

development:
    <<: *the_recurring_job

mrj avatar Apr 30 '25 19:04 mrj

Hey @rbarrera87, this doesn't seem related to Solid Queue. Solid Queue relies on ActiveSupport::ConfigurationFile.parse to load the recurring configuration. Looks like this is related to https://github.com/ruby/psych/pull/487, and was worked around in Rails here, defaulting to unsafe_load. I think Rails v7.1.5.1 should already have this, though, so is it possible you're disabling psych 's unsafe_load in your app?

rosa avatar May 09 '25 19:05 rosa