delayed_job
delayed_job copied to clipboard
Delayed methods with kwargs not working using ruby 3.0.0
I recently upgraded our rails app to 6.1 running on ruby 3.0.0. I have now several parts of my code failing when calling methods with keyword arguments (or named parameters) in conjunction with delay. I can reproduce the issue in the rails console:
def my_delayed_method(foo:, bar:) puts foo, bar end
=> :my_delayed_method
my_delayed_method(foo: 'foo', bar: 'bar')
foo
bar
=> nil
delay.my_delayed_method(foo: 'foo', bar: 'bar')
Traceback (most recent call last):
2: from (irb):4:in `<main>'
1: from (irb):1:in `my_delayed_method'
ArgumentError (wrong number of arguments (given 1, expected 0; required keywords: foo, bar))
I think this has something to do with the separation of args and kwargs introduced in ruby 2.7. Does delayed_job support ruby 3 and I am missing something? Or is this a compatibility issue?
Rails Version: 6.1.0 Ruby Version: 3.0.0 Delayed Job Version: delayed_job_active_record (4.1.5) delayed_job (4.1.9)
Also encountering this issue, a backtrace is provided. Looks like #1130 has some progress on this already
app/models/<removed>/image_methods.rb:35:in `update_images_and_upsert!': wrong number of arguments (given 1, expected 0) (ArgumentError)
from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/performable_method.rb:26:in `perform'
from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/backend/base.rb:81:in `block in invoke_job'
from vendor/bundle/ruby/3.0.0/gems/bugsnag-6.19.0/lib/bugsnag/integrations/delayed_job.rb:30:in `block (2 levels) in <class:Bugsnag>'
from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/lifecycle.rb:79:in `block (2 levels) in add'
from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/lifecycle.rb:61:in `block in initialize'
from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/lifecycle.rb:79:in `block in add'
from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/lifecycle.rb:66:in `execute'
from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/lifecycle.rb:40:in `run_callbacks'
from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/backend/base.rb:78:in `invoke_job'
from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/worker.rb:230:in `block (2 levels) in run'
from vendor/ruby-3.0.0/lib/ruby/3.0.0/timeout.rb:97:in `block in timeout'
from vendor/ruby-3.0.0/lib/ruby/3.0.0/timeout.rb:107:in `timeout'
from vendor/bundle/ruby/3.0.0/gems/delayed_job-4.1.9/lib/delayed/worker.rb:230:in `block in run'
from vendor/ruby-3.0.0/lib/ruby/3.0.0/benchmark.rb:308:in `realtime'
[...]
Yes, with #1130 it seems to work.
Waiting on this, as well!
@albus522 it looks like you're one of the primary caretakers of this gem. There are a couple of proposed PRs that would supposedly make DelayedJob compatible with Ruby 3. Any chance we can get your involvement to help move forward with at least one of the proposed solutions?
Hey @albus522! So sorry to bother you again. Any chance we could get your eyes on this?
Ruby 2.7 is EOL on March 31st and this is still broken which is a shame. It has been an obstacle in upgrading services to ruby 3x. There are a number of PRs addressing this issue, which can be leveraged but it would be nice to have an officially supported fix in.
https://endoflife.date/ruby
Keyword arguments have a lot of hidden complexity to implement for a background task which is why background job libraries are opting not to support them. This is not a ruby 2.7 compatibility thing. It is a complex ongoing support thing.
I don't expect Delayed Job will be adding support for this.
ok good to know. thanks!
Well, this is a sad discovery during an upgrade process. I'd like to learn more about other the other bg job libraries that are having issues or the specific issues in delayed_job. Having a bg job library not support kwargs isn't stellar for developer experience.
Also, it seems Betterment's delayed gem has taken up the torch and supports kwargs for those who don't want to revert to positional args.
In any case, much gratitude to the delayed_job contribs, we've relied on this library for a long time. Thank you :)