Problem loading job classes with autoloading#151
Conversation
If you pass a string for the job class, and the constant has already been loaded, the world is a happy place. However, if the constant has not yet been loaded (lazy loading in Rails for example) then this breaks. This fix attempts to autoload the constant to fix this issue.
resolve job classes that have not been loaded yet
|
Hi and thanks for the PR! Would you be able to write one or more tests proving the new code works as expected? Hopefully those tests can fail against master but pass on your branch. Earliest I'd be able to write those myself would probably be early next week, but if you could provide them, that would be super helpful. |
|
Hey @kenaniah - sorry for the delay. I'll see what I can do to get some additional tests in place this week. |
|
@kenaniah - just an update that I have not forgotten about this - I just have not been able to get to it yet. Hoping I can in the next few days. |
|
@noiseunion I think you forgot about this 😛 |
|
@jkeen - yes I did forget!!! 😬 Sorry about that. I will make some time this week to write some tests. |
|
UPDATE - I have started trying to write tests for this. However, in all honesty, I have not yet figured out how best to do so. Somehow I have to for lazy loading of class within the test and I honestly am not really sure how best to do that at the moment. I am definitely open to any suggestions 😄 |
If you pass a string value in for the class name, the
Module.const_defined?will not return true if the constant has not yet been loaded. In a Rails environment this can be a bummer due to the lazy loading in Rails. To address this, we can instead attempt to load the const and if a NameError occurs, we'll just returnnilas the original code would have done.I ran into this when using the
#push_bulkfeature of Sidekiq. Jobs created using that method did not get created properly as status workers if the class name was a string and not yet loaded.