English 中文(简体)
不装载铁路环境的废墟
原标题:ruby resque without loading rails environment

我有一位工作出色但太慢的转播工人。 造成这种情况的主要原因是,Im采用主动方式,必须装满至少需要10-20秒钟的整个环境(在Im使用Heroku和在工人经营时支付工资时,我没有在任何时候保留一名经营工人)。 I m利用转播工人进行放牧和安放;从外部网站上公布数据,然后将数据输入我的数据库。

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.

或者,如果我应当摘取法典(使用积极记录),其中哪些数字显示与外部数据做些什么,将其从工人手中移出,并重新输入数据?

希望是有意义的。

问题回答

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

我试图这样做。 承担我的震 res频率任务,是<条码>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

我用需要铁路环境的纸张片 g。

铁路boot的陷阱确实很缓慢;它打算继续运行,直到某些时间重新启用(消除可能存在的一些记忆泄露,任何软件都不会是免费的),而且无意被用作一个为一项请求而发射、然后关闭的网站。

这种使用比一种文字更类似。 如果你需要用浏览器发射,你可以很容易地使用Erubis,在文字中书写和使用主动记录(我认为可以在铁路之外使用)或类似的抽象层。 就小任务而言,我只使用

利用dler子在没有铁路申请的情况下积极与你进行cord和其他 g。

require  rubygems 
require  logger 
require  active_record 
require  bundler 

require "active_support"

require "spreadsheet"

require  net/ping 

require  net/http 

Bundler.setup

Bundler.require(:default) if defined?(Bundler)

$config_logger = Logger.new("./log/dev.log")



  class Dbconnect

     def  initialize
       @settings = YAML.load_file( ./config/database.yml )["development"]
       @adapter = @settings["adapter"] if @settings["adapter"]
       @database = @settings["database"] if @settings["database"]
       @pool = @settings["pool"] if @settings["pool"]
       @timeout = @settings["timeout"] if @settings["timeout"]
    end

    def connect_to_db
      ActiveRecord::Base.establish_connection(
        :adapter => @adapter,
        :database => @database,
        :reconnect => @reconnect,
        :pool => @pool,
        :timeout => @timeout)

      $config_logger.info "
  db Connected: to => #{@database}  "
    end
  end

end  

}


Example Gemfile : 


source "http://rubygems.org"

gem  mail 

gem "escape_utils"

gem  json ,:require => "json"

gem  json_pure 

gem  resque 

gem  resque-scheduler 

gem  redis-namespace 

gem  resque-status 

gem  rake 

gem  em-udns 

gem  sqlite3 

gem  spreadsheet 

gem  activerecord ,  3.2.1 , :require => "active_record"

gem  net-scp , :require =>  net/scp 

gem  net-sftp , :require =>  net/sftp 

gem  net-ssh , :require =>  net/ssh 

gem  dir 

gem  amatch 

gem  haml 

gem  net-ping 



gem install bundler

其余部分:





相关问题
Codeigniter WHERE on "AS" field

I have a query where I need to modify the selected data and I want to limit my results of that data. For instance: SELECT table_id, radians( 25 ) AS rad FROM test_table WHERE rad < 5 ORDER BY rad ...

Problem find joined table in rails

I have model represent association rule (Body => Head) def Item has_many :heads has_many :bodies ... end def Rule has_many :heads has_many :bodies ... end def Body belongs_to :item belongs_to :rule ...

FreeTDS Bad token from the server (SQL Server)

Today we had a lot more activity than normal between our Ruby on Rails application and our remote legacy SQL Server 2005 database, and we started getting the error below intermittently. What is is? ...

Castle ActiveRecord: one-to-one

While playing around with one-to-one associations in castle activerecord I stumbled upon the following problem: I m trying to model a one-to-one relationship (user-userprofile in this case). I ...

Sending email updates: model or observer?

I have an Event model, which stores an event feed for each user. I also need to email the updates to users which have enabled email notifications in their profile. From an architectural point of view,...

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

热门标签