红宝石resque不加载Rails环境 [英] ruby resque without loading rails environment

查看:172
本文介绍了红宝石resque不加载Rails环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个resque工人伟大的工程,但实在是太慢了。主要的原因是我使用的ActiveRecord,不得不将整个环境,至少需要10-20秒的时间来加载了(我不保持一个正在运行的工作在任何时候都因为我使用Heroku和支付对于当时的工人运行)。我使用的是resque工人抢&安培;从外部网站的分析数据,然后倾倒的数据到我的数据库。

I have a resque worker which works great but is just too slow. The main reason for this is I'm using activerecord and having to load the entire environment which takes at least 10-20 seconds just to load up (I don't keep a running worker at all times as I'm using Heroku and pay for the time the worker runs). I'm using a resque worker to grab & parse data from an external website and then dumping the data into my database.

我的问题是我是否应该重写不使用Rails的,而使用DataMapper的方法?还是其他什么东西这将载入速度比ActiveRecord的。

My question is whether I should rewrite the method to not use Rails and instead use DataMapper? Or something else which would load faster than activerecord.

或者如果我应该提取code(使用ActiveRecord的),它计算出如何处理外部数据并将其移出的工人,并返回到应用程序?

Or If I should extract the code (using ActiveRecord) which figures out what to do with the external data and move it out of the worker and back into the app?

希望是有道理的。

推荐答案

我有同样的问题。 你可以设置你的耙resque环境:设置rake任务

I have the same problem. you could setup your environment on the rake resque:setup rake task

我想这一点。假设我耙resque任务是在的lib /任务/ resque.rake

I tried this. assuming my rake resque task is on lib/tasks/resque.rake

require "resque/tasks"

task "resque:setup" do
  root_path = "#{File.dirname(__FILE__)}/../.."

  db_config = YAML::load(File.open(File.join(root_path,'config','database.yml')))["development"]
  ActiveRecord::Base.establish_connection(db_config)

  require "#{root_path}/app/workers/photo_downloader.rb" #workers

  #Dir.glob("#{root_path}/app/models/*").each { |r| puts r; require r } #require all model

  require "#{root_path}/app/models/photo.rb" # require model individually
end

我还没有完全成功怎么一回事,因为我用回形针宝石需要Rails环境

I haven't completely success beacuse I use the Paperclip gem which require rails environment

这篇关于红宝石resque不加载Rails环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆