views:

50

answers:

2

I am calling function with LoadData.send_later(:test). LoadData is my class and test is my method.

It's working fine while i am running rake jobs:work.

But when i am running script/delayed_job start or run that time delayed_job.log shows error like

TEastern Daylight Time: *** Starting job worker delayed_job host:KShah pid:5968
TEastern Daylight Time: * [Worker(delayed_job host:KShah pid:5968)] acquired lock on    LoadData.load_test_data_with_delayed_job
Could not load object for job: uninitialized constant LoadData
TEastern Daylight Time: * [JOB] delayed_job host:KShah pid:5968 completed after 0.0310
TEastern Daylight Time: 1 jobs processed at 10.6383 j/s, 0 failed ...

Any solution??

A: 

Try doing this:

Delayed::Job.enqueue LoadData.test

Also, a big gotcha that took me while to realize... if you make changes to the code restart rake jobs:work!

Tom
getting same error yet.. I have LoadData class in my lib/tasks folder. will it create problem? Any suggestion for it?
krunal shah
What happens when you run the task normally and not through DJ?
Tom
+1  A: 

Try putting include LoadData in an initializer. I seem to remember DelayedJob including activerecord classes, notifiers etc, but not custom classes. Personally I'd put the class in your models directory. It's still dealing with data, even if it's not activerecord.

mark
yes i have put LoadData in intializers and it's working fine now...
krunal shah
Can you accept my answer if this works ok for you too. :)Also, just to be sure, I meant create a file delayed_job.rb in initialisers and the line "include LoadData" therein.
mark
i have include LoadData in delayed_job.rb and i am getting this error "rake aborted!wrong argument type Class (expected Module)".
krunal shah