Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

recurring task argument not successfully passing all ActiveJob supported types #183

Closed
hms opened this issue Mar 22, 2024 · 8 comments
Closed

Comments

@hms
Copy link
Contributor

hms commented Mar 22, 2024

I ran into a problem with passing an ActiveSupport::Duration to a recurring job.

I built a couple of jobs that just pass arguments and check that they are received as the expected types. I tested each of the supported type described on the Rails guides Active Job Basics.

  • I was unable to successfully pass any ActiveSupport supported datatypes: TimeWithZone, Duration, or HasWithIndifferentAccess. I tried positional and kwargs and regardless of how I attempted to pass the argument, they are received by the job as a string.
  • I was unable to figure out pass a symbol as an argument in any permutation: arg: :sym, arg: ":sym", arg: 'sym'.to_sym
  • I made a quick test with an ActiveJob custom serializer, but my custom types where also being processed as strings.

Sample solid_queue.yml:

default: &default
  dispatchers:
    - polling_interval: 1
      batch_size: 500
      recurring_tasks:
        rails_types_job:
          class: RailsTypesJob
          args: [ 10.minutes, { twt: Time.current, duration: 10.minutes } ]
          schedule: every 1 minute
@rosa
Copy link
Member

rosa commented Mar 22, 2024

Hey @hms, yes, this is expected as the way this is implemented allows only types supported by YAML. I went for this for simplicity, pretty much mirroring the way resque-scheduler's static schedules work, as this is what we've used before when we couldn't rely on Unix's cron, and it's covered everything we needed. More complex arguments can be supported in different ways directly on the job itself.

However, I'd be happy to consider any contributions that enhance this!

@hms
Copy link
Contributor Author

hms commented Mar 22, 2024

Hi Rosa,

Once I figure out how to get Docker and the tests working on my fork, I might make a run at this and #176 (something that would make my life a little better). Until then, could we update the Readme with the officially supported argument types?

@rosa
Copy link
Member

rosa commented Mar 22, 2024

Of course, sure thing! 🙏

What's not working for you when you run bin/setup?

@hms
Copy link
Contributor Author

hms commented Apr 5, 2024

@rosa Sorry for going radio silent, getting crushed on a delivery. Can I get back to this in a week or 2?

@rosa
Copy link
Member

rosa commented Apr 5, 2024

Hey @hms, of course, no worries at all! 🙏

@rosa
Copy link
Member

rosa commented Jan 16, 2025

Finally going to close this one as not planned.

@rosa rosa closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2025
@hms
Copy link
Contributor Author

hms commented Jan 18, 2025

@rosa

I'm sorry for not following up on this. Turns out with a little ERB or paying attention to the Pysch docs, the above example is possible. I just didn't realize that I could use ERB in the config.yml files. I just did a quick scan of the docs and the fact that one can use ERB isn't mentioned.

If you would like a PR on the readme.md to call out the ERB processing is supported, I'm happy to make one.

@rosa
Copy link
Member

rosa commented Jan 20, 2025

@hms no worries at all! I think the problem with using ERB and manually serializing the arguments (which might be confusing or not) is that it'd be evaluated when the configuration is loaded. That is, Time.current in your example will always be the same value for all executions of the job, the time when the configuration was loaded. This is probably not what you want here. 10.minutes would work, though.

I just did a quick scan of the docs and the fact that one can use ERB isn't mentioned.

This is true for all configuration files loaded via ActiveSupport::ConfigurationFile.parse, which I think applies to all configuration files in Rails, so I didn't think of explicitly calling this out, but I think it'd be useful as a reminder for people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants