2013-05-30 47 views
0

我正在使用delayed_jobs在後臺運行任務。在本地主機上工作,但在Heroku上失敗

我開始使用ajax的任務,工作人員獲取一些uuid並寫入以緩存任務的狀態和結果。

然後我使用另一個Ajax輪詢每秒鐘,看看我是否有結果。

它在我的本地主機上運行良好,但是當我上傳到heroku時,它不會。

我檢查了日誌,我可以看到工作人員可以讀取它已經寫入的緩存,但是當主線程嘗試訪問它時它是空的。

我正在使用瘦服務器,memcachier和dalli。

這是用於寫入到高速緩存的代碼:

 
def self.get_meta_info(link_url,job_uuid) 
    begin 
     #.......... 
     result = { 
      title: "stuff here..." 

     } 
     #.......... 

     Rails.cache.write({job_uuid: job_uuid,type: 'result'},result.to_json) 
     Rails.cache.write({job_uuid: job_uuid,type: 'status'},'success') 

#the next to lines return the data in the logs 
     Rails.logger.info("get_meta_info written to hash at #{job_uuid}") 
     Rails.logger.info("get_meta_info result for #{job_uuid} was: #{Rails.cache.read({job_uuid: job_uuid,type: 'result'})}") 

    rescue Exception => ex 
     Rails.cache.write({job_uuid: job_uuid,type: 'result'},ex) 
     Rails.cache.write({job_uuid: job_uuid,type: 'status'},'error') 
    end 
    end 

這是服務器端代碼我使用的輪詢:

 
    def get_meta_info_result 
    job_uuid = params[:job_uuid] 
    status = Rails.cache.read({job_uuid: job_uuid,type: 'status'}) 
    #the next to lines return nothing in the logs 
    Rails.logger.info("nlp_provider_controller.get_meta_info_result for uuid #{job_uuid} read status #{status}") 
    Rails.logger.info("nlp_provider_controller.get_meta_info_result for uuid #{job_uuid} read result #{Rails.cache.read({job_uuid: job_uuid,type: 'result'})}") 
    respond_to do |format| 
     if status=='success' 
     format.json {render json: Rails.cache.read({job_uuid: job_uuid,type: 'result'})} 
     elsif status=='error' 
     format.json{render :nothing => true, status: :no_content } 
     else 
     format.json{render :nothing => true, status: :partial_content } 
     end 
    end 

I(它是由AJAX每秒調用)不知道如何解決這個問題。

坦克你!

回答

0

兩天來解決這個問題。愚蠢的錯誤。

有兩個配置文件,development.rb和production.rb。不是我不知道,但通常我在一個單獨的初始化程序中配置。

我在開發中配置了Redis,而不是在生產中配置了Redis。

補充:

redis_url = ENV["REDISTOGO_URL"] || "redis://127.0.0.1:6379/0/MyApp" 
MyApp::Application.config.cache_store = :redis_store, redis_url 

(基於:http://blog.jerodsanto.net/2011/06/connecting-node-js-to-redis-to-go-on-heroku/

和它的作品。

相關問題