I give up, I've tried everything and back again and for the life of me I can't
include / require my common methods file in my rake task.
First I thought that if you added a file in the
lib folder and made sure it was in the load path that it would be available everywhere? Doesn't seem to be the case?
Also Do I
include or do I
And where in my
rake task do I do this?
I have defined this file to contain all my shared methods. Its in
/my_app/lib/common.rb and it looks like this:
module Common def is_amazon_api_available? Api.find(1).available end def turn_off_amazon_api_access Api.find(1).update(available: false) end def turn_on_amazon_api_access Api.find(1).update(available: true) end end
rake task looks like this:
require 'aws-sdk' #include 'common.rb' #require 'common.rb' desc 'Go thru all Shops' task :check_amazon_order_status => :environment do # require 'common.rb' # require "/common.rb" start_fixing_order_status end def start_fixing_order_status loop do if is_amazon_api_available? turn_off_amazon_api_access shops = Shop.where(setup: true, subscribed: true).order('id ASC') shop_count = 1 shops.each do |shop| setup_shopify_session(shop) get_all_orders_for_shop(shop) shop_count += 1 end turn_on_amazon_api_access break else sleep(5.minutes) end end end