0

I have a rake task

namespace :authentication do

desc "Automatically runs authentication tester"

task :tester => :environment do
  begin
    Auth.perform
  rescue
    SystemEvent.error(50049, "Authentication Tester Finished Unsuccessfully.")
  end
 end
end

in my Auth.perform, I have used,

Customer.first.symbol

I am loading Customer from database. But it always comes to the rescue block saying

undefined method 'symbol' for nil:class

In my application.rb

config.autoload_paths += Dir.glob("#{Rails.root}/lib/**/*").select{|d| File.directory?(d)}
config.autoload_paths += Dir.glob("#{Rails.root}/app/models/**/*").select{|d| File.directory?(d)}
config.autoload_paths += ["#{Rails.root}/services/"]

This calls Auth.perform in development. Only in production it comes to rescue block. Is this something because I am missing?

require 'rake'

Please provide a solution. It has been one week I am picking my head.

Please Note: this rake task is called by a cron running in another instance.

Suganya Selvarajan
  • 962
  • 1
  • 11
  • 33
  • 1
    Are there customers in the production database? – ReggieB Feb 21 '17 at 15:16
  • It's way harder to debug if you don't have a stacktrace for the error (the way you are rescuing will lose it). It's best not to have "naked" rescues in this way (see [here](http://stackoverflow.com/questions/10048173/why-is-it-a-bad-style-to-rescue-exception-e-in-ruby)), but at minimum you could change the rescue to `rescue StandardError => e` and then in the rescue block read `e.class` (the type of error), `e.message`, and `e.backtrace`. Also, if you can SSH into production and run the task from there, you'd have an easier time seeing the results – max pleaner Feb 21 '17 at 19:24
  • @ReggieB Yes there are customers in my production DB. – Suganya Selvarajan Feb 22 '17 at 06:18
  • `Undefined method symbol for nil class` Check your rails console if there are any customer in the DB, because it seems there is not. – theterminalguy Feb 22 '17 at 06:40
  • The customers table is what is our base. It is never empty. – Suganya Selvarajan Feb 22 '17 at 06:51

0 Answers0