film42 / sidekiq-rs

A port of sidekiq to rust using tokio
MIT License
95 stars 10 forks source link

Sidekiq server error with jobs enqueued via Rust by not via Ruby #10

Closed justmark closed 1 year ago

justmark commented 1 year ago

Hi,

Just updated to 0.6.0. All my current jobs have been created via our Ruby platform. Today I started some new workers being generated through sidekiq-rs. The jobs are showing up on the server, but the server is reporting an error and saving the jobs as retries.

Here is the code for creating the job via your crate-level method:

sidekiq::perform_async(
                    sidekiq,
                    "V1StatisticsWorker".into(),
                    "v1_statistics".into(),
                    payload_data,
                )
                .await;

On my Sidekiq server, the job is showing up with the correct Job and Queue name, but the error showing up is: NameError: uninitialized constant V1StatisticsWorker - is this possibly an issue with the namespacing?

If I generate the job from Ruby, no error shows up.

film42 commented 1 year ago

Is your ruby worker class written like

module V1
  class StatisticsWorker
  end
end

by chance?

If so you probably need your worker name to be V1::StatisticsWorker.

You can also call perform_async on the worker directly and override the worker name via the trait implementation: https://github.com/film42/sidekiq-rs#customizing-the-worker-name-for-workers-under-a-nested-ruby-module

mod v1 {

#[async_trait]
impl sidekiq::Worker<()> for StatisticsWorker {
// ...
    fn class_name() -> String
    where
        Self: Sized,
    {
        "V1::StatisticsWorker".to_string()
    }
// ...
}

}

And then calling from the helper methods on the worker trait:

v1::StatisticsWorker::opts().queue("v1_statistics".into()).perform_async(sidekiq, payload_data).await?;
justmark commented 1 year ago

Hi,

No, the Ruby classes themselves aren't in a module. Here's the same Ruby definition:

class V1StatisticsWorker
  include Sidekiq::Worker
  sidekiq_options queue: :v1_statistics

  def perform(payload)
  end
end

Mark

film42 commented 1 year ago

👍 Good to know. Let me see if I can reproduce with that ruby worker.

film42 commented 1 year ago

I can't seem to reproduce. Does that demo I opened a PR for work for you?

justmark commented 1 year ago

We’re all good with v0.6.1.

Thanks for this!