Rails 请教在 action 中使用 Thread

randr · December 25, 2014 · Last by randr replied at December 25, 2014 · 1612 hits

服务器:passenger+apache rails: 4.0.3

发现一个很奇怪的问题。 下面这样的写法:

def copy
  @site = Site.find_by_id(params[:id])
  Thread.new do
    Site.transaction do
        @site.copy_relation_data
        @site.update_attributes(:copy_flag=>true)
    end
  end
end

当 passenger reload 一次代码之后,Thread 会被终止掉,没有问题,但是为什么 transaction 也会被 commit?

请大牛们帮忙解释一下

上 mq,在 action 里这么开线程作死

#1 楼 @saiga 谢谢。后面改了,只是不知道这个 transaction 为什么会 commit

You need to Sign in before reply, if you don't have an account, please Sign up first.