2013-05-30 43 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/

和它的作品。

相关问题