bensheldon / good_job

Multithreaded, Postgres-based, Active Job backend for Ruby on Rails.
https://goodjob-demo.herokuapp.com/
MIT License
2.53k stars 190 forks source link

Unable to use labels with kwargs in job initializer #1350

Open gap777 opened 2 months ago

gap777 commented 2 months ago

Hi, Just trying out labels, and it appears that if I have kwargs in the initializer of my jobs, I can't use labels.

My job:

class TestJob < ApplicationJob
    include GoodJob::ActiveJobExtensions::Concurrency
    include GoodJob::ActiveJobExtensions::Labels

  def perform(kwarg1:, kwarg2:)
     good_job_labels << did_the_thing? ? 'Foo' : 'Bar'
  end

I get this in the error logs:

wrong number of arguments (given 1, expected 0; required keywords: kwarg1, kwarg2)
bensheldon commented 2 months ago

This is an Active Job thing: ActiveJob::Base#initialize should never have its method signature changed. I think you mean to customize the #perform signature to pass parameters to a job.

gap777 commented 2 months ago

@bensheldon 🤦 I created that example for this, trying to reproduce a more complicated example in my codebase. I don't have that obvious mistake in the real thing. ;-)

But still... I'm seeing that error about wrong number of arguments for perform when I add in the labels mixin. Can you try that on your end, with a perform having kwargs and the label mixin present?

bensheldon commented 1 month ago

@gap777 sorry, I missed the reply. Can you share the code (both your job and the calling code) that you're using?