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

ArgumentError: wrong number of arguments (given 1, expected 0; required keyword: schedule) - cron #546

Closed
hiendinhngoc opened this issue Mar 28, 2022 · 9 comments · Fixed by #548

Comments

@hiendinhngoc
Copy link

hiendinhngoc commented Mar 28, 2022

I got this error when setting for my job with argument:

class External::BlazerJob < ApplicationJob
  queue_as :default

  def perform(schedule:)
    Blazer.run_checks(schedule: schedule)
  end
end

and here is my setting:

five_mins_interval_check_task: {
        cron: "10/5 * * * *",
        class: "External::BlazerJob",
        args: {schedule: "5 minutes"},
        desciption: "Run 5-minute interval checks",
      }

I expected the job should be Blazer.run_checks(schedule: "5 minutes") after passing the argument.

What was I wrong here?

@bensheldon
Copy link
Owner

@hiendinhngoc Try passing the args as an array:

args: [{schedule: "5 minutes"}],

@bensheldon
Copy link
Owner

🙌 woot!

@hiendinhngoc
Copy link
Author

hiendinhngoc commented Mar 29, 2022

I am sorry, reopen this because after deploying to staging, I'm still getting this error regarding the update, active job params:

{
  "job_id": "c8fc128a-05de-495d-9d68-cu92483c56d8",
  "locale": "en",
  "priority": null,
  "timezone": "UTC",
  "arguments": [
    {
      "schedule": "5 minutes",
      "_aj_hash_with_indifferent_access": true
    }
  ],
  "job_class": "External::BlazerJob",
  "executions": 0,
  "queue_name": "default",
  "enqueued_at": "2022-03-29T04:25:00Z",
  "provider_job_id": null,
  "exception_executions": {
  }
}

Does it due to the old jobs which were already in the queue before? If yes how do I remove all the old ones?
PS: Get error also with params with more than one args like this: args: [{from: 7.days}, {to: 6.days}]

@hiendinhngoc hiendinhngoc reopened this Mar 29, 2022
@bensheldon
Copy link
Owner

@hiendinhngoc I looked into it deeper and I think it may not work with kwargs. I'm a bit stumped on how to appropriately construct/pass a configuration value that has both args and kwargs to a method. Could you share the version of Ruby, and Ruby on Rails you're using?

I'm doing some more research on how to handle this.

@hiendinhngoc
Copy link
Author

hiendinhngoc commented Mar 29, 2022

@bensheldon I am using ruby 3.0.2 and rails 6.0.4

@bensheldon
Copy link
Owner

@hiendinhngoc I just released a new version (v2.11.3) that splits out an explicit kwargs.

five_mins_interval_check_task: {
        cron: "10/5 * * * *",
        class: "External::BlazerJob",
        kwargs: {schedule: "5 minutes"}, # <-- change this to `kwargs`
        desciption: "Run 5-minute interval checks",
      }

@hiendinhngoc
Copy link
Author

@bensheldon thank you for your quick support. If the arguments are more than one, what should be correct?
[{from: 7.days}, {to: 6.days}] or {from: 7.days, to: 6.days}

@bensheldon
Copy link
Owner

Yay! One single hash.

@hiendinhngoc
Copy link
Author

thank you so much!

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

Successfully merging a pull request may close this issue.

2 participants