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

Unique args in combination with sidekiq cron contains _aj_symbol_keys #363

Closed
Laykou opened this issue Jan 9, 2019 · 2 comments
Closed

Comments

@Laykou
Copy link

Laykou commented Jan 9, 2019

Describe the bug
When used together with sidekiq-cron, the hashes may include _aj_symbol_keys keys which then confuses unique_arg method.

Expected behavior
The job to be executed.

Current behavior
The job was created. I can see the unique digest is created and also sidekiq-status creates initial record in Redis, BUT the job is NOT executed.

The unique digest is not removed however no job is running and it looks like nothing else happened.

Worker class

class MyWorker
  include Sidekiq::Worker
  include Sidekiq::Status::Worker

  sidekiq_options retry: 0, lock: :until_executed, lock_expiration: 15.minutes.to_i, queue: :system_schedulers

  def self.unique_args(args)
    # Here I've noticed that the there is `args.first['params']['_aj_symbol_keys']`
    args
  end

  def perform(args)
    # args['sleep'] == '10'
    # args['params'] == { foo1: 'bar1', foo2: 'bar2' }
  end
end

Additional context

# schedule.yml

my_worker:
    cron: "* * * * *"
    class: "MyWorker"
    args:
      sleeps: "10"
      params:
        foo1: "bar1"
        foo2: "bar2"

I think unique_jobs should try to ActiveJob::Arguments.deserialize args before using them.

@Laykou
Copy link
Author

Laykou commented Jan 9, 2019

My workaround is:

  • recursively stringify all the keys and values (because that's what deserializer can take)
  • deserialize (which removes these ActiveJob keys)
def self.unique_args(args)
  arguments =stringify(args)

  ActiveJob::Arguments.deserialize(arguments)
end

def self.stringify(input)
  case input
  when Hash
    input.map do |key, value|
      [key.to_s, stringify(value)]
    end.to_h
  when Array
    input.map { |e| stringify(e) }
  else
    input.to_s
  end
end

@mhenrixon
Copy link
Owner

I don't plan on supporting ActiveJob at all. Neither sidekiq-status nor sidekiq-cron has anything to do with the _aj_symbol_keys. That is all ActiveJob and I strongly recommend you stop using it and start using Sidekiq directly. In your example you don't even use ApplicationJob or ActiveJob::Base anywhere so I really don't see why you are using ActiveJob at all. Use MyWorker.perform_async instead of MyWorker.perform_later.

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