简体   繁体   中英

Rails 3 uninitialized constant when using thread

i am running rails 3 thread to improve the performance of the rake task. sometimes i am getting uninitialized constant when i am trying to access outside class from my current class. as an example when i am trying to access NotificationService class from NotificationApp as shown below then getting error as uninitialized constant NotificationService . This error is not coming every time. sometimes rake task is running fine without the error and sometimes same rake is failing with uninitialized constant. what could be the reason for this and how can i fix this issue?

class NotificationApp < ActiveRecord::Base
  def signal_event
    NotificationService.notify
  end
end

Make sure your NotificationService class is in a file named app/services/notification_service.rb and that you are loading this services directory.

Also as you are using threads, make sure to join all the threads after calling them

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM